How can I accomplish the equivalent of pytest's `--boxed` option in nosetests?

30 views
Skip to first unread message

Vitaly Krug

unread,
Mar 17, 2018, 1:45:16 PM3/17/18
to nose-users
[I can't figure out how to accomplish this from `nosetests --help` and googling didn't help either]

I just ran into this issue while implementing unit tests for an asynchronous module based on the Twisted reactor event loop. Once the test starts, it initiates some asynchronous activities and then calls `reactor.run()` which blocks until something in the test calls `reactor.stop()`. Once stopped, subsequent tests in the test suite that need to call `reactor.run()` fail with the `twisted.internet.error.ReactorNotRestartable` exception. Twisted doesn't have the notion of creating additional event loops - there is only one by design, and it can't be restarted once stopped (also by design).

So, the only way that I can run more than one test, is to run each test in process isolation. pytest supports the `--boxed` option that guarantees that each test will run in its own process that won't be reused for any other tests. 

I tried nosetests options `--with-isolation` and `--processes`, but they don't help.

Vitaly Krug

unread,
Mar 17, 2018, 2:06:22 PM3/17/18
to nose-users
P.S., the `--boxed` option is provided to pytest via the `pytest-xdist` plugin.

Vitaly Krug

unread,
Mar 21, 2018, 8:45:20 PM3/21/18
to nose-users
Does the lack of replies mean that I am out of luck?

Nathan

unread,
Mar 22, 2018, 11:27:52 AM3/22/18
to nose-...@googlegroups.com
I don't know how you would use nose to run twisted code, but twisted ships with their own test runner called "trial" that you could certainly use instead.  trial was the first test runner I ever encountered, back in the day.


On Wed, Mar 21, 2018 at 6:45 PM Vitaly Krug <vital...@gmail.com> wrote:
Does the lack of replies mean that I am out of luck?

--
You received this message because you are subscribed to the Google Groups "nose-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nose-users+...@googlegroups.com.
To post to this group, send email to nose-...@googlegroups.com.
Visit this group at https://groups.google.com/group/nose-users.
For more options, visit https://groups.google.com/d/optout.

Vitaly Krug

unread,
Mar 22, 2018, 1:15:14 PM3/22/18
to nose-...@googlegroups.com
Thank you for the response. That's what I feared. In the Pika ANQP client package, we have adapters wrapping various supported ioloops, including twisted reactor, and a shared  set of integration tests that, along with all the others, are executed via noseyests 

Vitaly Krug

unread,
Mar 23, 2018, 12:16:01 AM3/23/18
to nose-users
Okay, I didn't discover a solution for boxing tests via nose, but I solved the actual problem that I was trying to work around in my tests. It turns out that twisted.internet automagically simulates a class in the the twisted.internet.reactor module, setting its `__class__` attribute to the loop class that it selected for the current platform. So, in my tests, I am able to create a new instance of that loop class via `twisted.internet.reactor.__class__()`. FYI.
Reply all
Reply to author
Forward
0 new messages