Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python Nose tests from generator not running concurrently

Tags:

python

nose

Given the following:

from time import sleep

def runTest(a):
    sleep(1)
    assert a >= 0

def test_all():
    for i in range(5):
        yield (runTest, i)

I would expect the five tests to get run in parallel running with nosetests --processes=8 and thus run in approximately one second — however, it takes just over five seconds to run: they appear to be running sequentially and not concurrently.

According to the nose documentation, the multiprocess plugin has supported test generators (as the nose documentation calls them) since 1.1: I'm using nose 1.3.0 so it should be supported. Adding _multiprocess_can_split_ = True does make any difference, as one would expect, as fixtures are not used.

How do I get these five tests to run concurrently?

like image 900
gsnedders Avatar asked May 04 '13 21:05

gsnedders


People also ask

Why use nose instead of unittest in Python?

Python’s standard unittest module loses ground to other Python test automation frameworks, as it requires a lot of boilerplate code and tests have to be included into large test classes. Nose is a popular alternative if you still want to use the default Python unit testing framework.

Can I run nose tests with pytest?

pytest has basic support for running tests written for nose. python setup.py develop # make sure tests can import our package pytest # instead of 'nosetests' and you should be able to run your nose style tests and make use of pytest’s capabilities.

Should you use nose2 Python for test automation?

If you are familiar with unittest – Python’s standard library and prefer the same over other test automation frameworks in Python, then you should have a brief look at Nose2 Python. Nose2 Python is based on unittest and adds more value to the framework through its rich plugin ecosystem. In simple terms, Nose2 is an extension of the unittest module.

How to enable logging in nose2 Python?

The logs are appended to the Python Nose test report of the failed tests. The logging functionality in Nose2 Python can be set either from the terminal (when triggering the execution command) or by adding the configuration in a unittest.cfg (or nose2.cfg) file. I prefer the –log-capture command-line option to enable logging in Nose2.


1 Answers

According to nose's author, on the mailing list, the multiprocess plugin does not work with generators in 1.3 (a known bug), and he recommends sticking with 1.1 if one needs it to work.

like image 146
gsnedders Avatar answered Nov 15 '22 01:11

gsnedders