Nose2 vs py.test with isolated processes

We used nosetest to run and collect our unittests (they are all written as python unitests, which we like). What we like about the nose:

  • uses standard python unit tests (we like the structure this imposes).
  • supports report coverage and test result in xml (for jenkins).

What we are missing is a good way to run tests in isolated processes, while maintaining a good error reload (we test C ++ libraries through python, so segfaults should not be catastrophic). seems to be no longer supported, but we have some problems with it.

We are trying to find out if we should - fix / use the nasal tube - switch to nose2 and write pulp 2. - use pytest or some other testing framework.

We would rather use a good community approach. It seems our problem (C ++ plugins requiring good isolation) may be a common problem, but googling. I did not find any supported solutions. The board appreciated the more experienced leaders.

+5
source share
1 answer

pytest has an xdist plugin that provides an option --boxed to run each test in a controlled subprocess. Here is an example:

# content of test_module.py

import pytest
import os
import time

# run test function 50 times with different argument
@pytest.mark.parametrize("arg", range(50))
def test_func(arg):
    time.sleep(0.05) # each tests takes a while
    if arg % 19 == 0: 
        os.kill(os.getpid(), 15)

If you run this with:

$ py.test --boxed
=========================== test session starts ============================
platform linux2 -- Python 2.7.3 -- pytest-2.3.0.dev8
plugins: xdist, bugzilla, cache, oejskit, cli, pep8, cov
collecting ... collected 50 items

test_module.py f..................f..................f...........

================================= FAILURES =================================
_______________________________ test_func[0] _______________________________
/home/hpk/tmp/doc-exec-420/test_module.py:6: running the test CRASHED with signal 15
______________________________ test_func[19] _______________________________
/home/hpk/tmp/doc-exec-420/test_module.py:6: running the test CRASHED with signal 15
______________________________ test_func[38] _______________________________
/home/hpk/tmp/doc-exec-420/test_module.py:6: running the test CRASHED with signal 15
=================== 3 failed, 47 passed in 3.41 seconds ====================

, , f . , xdist, ::

$ py.test --boxed -n3
=========================== test session starts ============================
platform linux2 -- Python 2.7.3 -- pytest-2.3.0.dev8
plugins: xdist, bugzilla, cache, oejskit, cli, pep8, cov
gw0 I / gw1 I / gw2 I
gw0 [50] / gw1 [50] / gw2 [50]

scheduling tests via LoadScheduling
..f...............f..................f............
================================= FAILURES =================================
_______________________________ test_func[0] _______________________________
[gw0] linux2 -- Python 2.7.3 /home/hpk/venv/1/bin/python
/home/hpk/tmp/doc-exec-420/test_module.py:6: running the test CRASHED with signal 15
______________________________ test_func[19] _______________________________
[gw2] linux2 -- Python 2.7.3 /home/hpk/venv/1/bin/python
/home/hpk/tmp/doc-exec-420/test_module.py:6: running the test CRASHED with signal 15
______________________________ test_func[38] _______________________________
[gw2] linux2 -- Python 2.7.3 /home/hpk/venv/1/bin/python
/home/hpk/tmp/doc-exec-420/test_module.py:6: running the test CRASHED with signal 15
=================== 3 failed, 47 passed in 2.03 seconds ====================

, . , , -n, . , , . .

+13

All Articles