<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Fri, May 8, 2015 at 2:35 PM, Luke Mergner <span dir="ltr">&lt;<a href="mailto:lmergner@gmail.com" target="_blank">lmergner@gmail.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><br><div class="gmail_extra"><div><div class="h5"><br><div class="gmail_quote">On Fri, May 8, 2015 at 8:45 AM, Carl Meyer <span dir="ltr">&lt;<a href="mailto:carl@oddbird.net" target="_blank">carl@oddbird.net</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi Luke,<br>
<div><div><br>
On 05/07/2015 07:03 PM, Luke Mergner wrote:<br>
&gt; I searched the list archives, Stack Overflow, Github, and the internet<br>
&gt; broadly, but did not see my question answered. This makes me think that<br>
&gt; I am approaching my problem from the wrong angle.<br>
&gt;<br>
&gt; I have a small Flask project which serves a few single-page-applications<br>
&gt; in several javascript frameworks. My goal is to learn to write js front<br>
&gt; end web applications. It was much easier for me to build the server in<br>
&gt; Flask, Jinja2, and SQLAlchemy rather than use Node, which many of the js<br>
&gt; framework  tutorials assume.<br>
&gt;<br>
&gt; On top of my unit tests written in python (pytest) and javascript<br>
&gt; (jasmine, jest, or karma), I also thought I’d write some integration<br>
&gt; tests with CasperJS or, later, to try PhantomCSS. The challenge here is<br>
&gt; that in order to automate the process I have to run a live server<br>
&gt; example (plenty of these around) while also running the CasperJS<br>
&gt; process. Since this is a learning project, none of this is necessary,<br>
&gt; but it helps me to learn how to do things “the right way.”<br>
&gt;<br>
&gt; Ideally, I’d like to run the CasperJS integration tests through pytest.<br>
&gt; I’ve spent some time sketching out a test runner in Python that collects<br>
&gt; the test_*.js files by name and runs them in a threaded subprocess. It<br>
&gt; catches the return code, etc., from which I can infer success or<br>
&gt; failure. (Cool! I wrote my first threaded module.) Then I thought, it<br>
&gt; sure would be nice to add this as a pytest-plugin, then the server can<br>
&gt; be started as a fixture and the tests added in the normal test discovery<br>
&gt; phase.<br>
&gt;<br>
&gt; There is actually a Github project that claims to do something like this<br>
&gt; for Django, but it doesn’t appear load or run the CasperJS files. The<br>
&gt; documentation for pytest allows for adding tests through the<br>
&gt; pytest_pycollect_additem hook. However, the functions assume an<br>
&gt; inspectable python object. Option one is to just add a naive python<br>
&gt; wrapper around the javascript tests and see what happens.<br>
&gt;<br>
&gt; Option two would be to wrap the subprocess call in a way that I can<br>
&gt; return a subclass of _pytest.python.Function or to create a subclass of<br>
&gt; _pytest.main.FSCollection which acts like the PyCollection? I’m<br>
&gt; wondering if I can write subclasses of the Collection/Session and<br>
&gt; Function classes that I run along with the PyCollection lifecycle. It<br>
&gt; seems like to do this right, you’d want to give pytest an Item or Node<br>
&gt; class that mimics what it expects from introspecting python code. This<br>
&gt; at least is what I think after looking at pytest source.<br>
&gt;<br>
&gt; Is this worth pursuing? Is there an obvious alternative, like Selenium?<br>
&gt; What can anyone recommend in terms of implementation?<br>
<br>
</div></div>Selenium is one obvious alternative, yes (and the one that I use). The<br>
advantage is that there is a Python Selenium webdriver library<br>
(<a href="https://pypi.python.org/pypi/selenium" target="_blank">https://pypi.python.org/pypi/selenium</a>) so you can write your Selenium<br>
tests in Python and avoid the &quot;how do I run tests written in JS from<br>
py.test&quot; problem. You can use Selenium with PhantomJS if you like, but<br>
you can also run your Selenium tests on real browsers (Firefox, Chrome,<br>
etc).<br>
<br>
If you do still want to run tests written in JS from Python, you can use<br>
the pytest_collect_file hook to implement arbitrary transformation of<br>
any type of file into a set of tests (this is what oejskit does). (For<br>
instance, I have a pytest plugin for testing templates using<br>
pytest_collect_file; the tests are written in YAML files and<br>
transparently discovered and run by py.test).<br></blockquote><div> </div></div></div></div>To both Carl and Marius,</div><div class="gmail_extra"><br></div><div class="gmail_extra">Thank you for taking the time to respond. Because I don&#39;t have programmers around to ask, having my questions taken seriously is very helpful for my thought process. </div><div class="gmail_extra"><br></div><div class="gmail_extra">I did see oejskit, but for some reason didn&#39;t look closely at the source. I shall do so. I have little faith in my own skills to innovate, but even a blind squirrel finds a nut once in a while. Besides, I&#39;ve noticed that testing tools really challenge one&#39;s understanding of a language.</div><div class="gmail_extra"><br></div><div class="gmail_extra">Perhaps because Javascript is exploding in complexity and the tools are evolving, transitioning from Python to Javascript (with a sane toolchain from writing to deploying) has been a real challenge.</div><div class="gmail_extra"><br></div><div class="gmail_extra">Best,</div><div class="gmail_extra"><br></div><div class="gmail_extra">Luke</div></div></blockquote><div><br></div><div>And to Jim to: Thank you. wsgidriver looks like a very interesting solution. </div></div><br></div></div>