Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to use Nose to run one test multiple times, concurrently?

Is it possible to use nose to run a single test concurrently (across multiple processes) and aggregate the result in to a single pass/fail result?

We have the need to run the same test multiple times concurrently to ensure resource locking isn't being affected. If nose can't do this, is there a specific testing/design pattern to follow to achieve this?

like image 798
Phillip B Oldham Avatar asked Nov 03 '10 14:11

Phillip B Oldham


2 Answers

This seems like something you want in the test definition itself because you want to assert on the aggregation of the results. I would take a look at using multiprocessing in the test. Create a pool to execute your code in parallel. You can use a Queue to aggregate the results.

like image 139
dietbuddha Avatar answered Sep 19 '22 06:09

dietbuddha


It is possible to run tests concurrently with nose:

Using the nose.plugin.multiprocess plugin, you can parallelize a test run across a configurable number of worker processes. While this can speed up CPU-bound test runs, it is mainly useful for IO-bound tests that spend most of their time waiting for data to arrive from someplace else and can benefit from parallelization.

I've adapted the plugin to run a single test in parallel as you want. Download from http://paste.pocoo.org/show/319470/ and save as nose/plugins/repeat.py. Then, in nose/plugins/builtin.py, add the line ('nose.plugins.repeat', 'RepeatMultiProcess'), to builtins. Call like this:

c:\python27\python nose-1.0.0\selftest.py --repeat-processes=2 --repeat-times=3 test2.py

Note: setup/teardown support might be broken. If so, the fix is simple, see comment in line

like image 9
TryPyPy Avatar answered Sep 18 '22 06:09

TryPyPy