I am trying to migrate a bunch of tests from nose
to pytest
and I am having trouble migrating one test that validates a whole process.
I have dumbed it down to represent my problem:
def is_equal(a, b):
assert a == b
def inner():
yield is_equal, 2, 2
yield is_equal, 3, 3
def test_simple():
yield is_equal, 0, 0
yield is_equal, 1, 1
for test in inner():
yield test
yield is_equal, 4, 4
yield is_equal, 5, 5
def test_complex():
integers = list()
def update_integers():
integers.extend([0, 1, 2, 3, 4, 5])
yield update_integers
for x in integers:
yield is_equal, x, x
test_simple
runs fine between nose
and pytest
, but test_complex
only runs the initial update_integers
test:
~/projects/testbox$ nosetests -v
test_nose_tests.test_simple(0, 0) ... ok
test_nose_tests.test_simple(1, 1) ... ok
test_nose_tests.test_simple(2, 2) ... ok
test_nose_tests.test_simple(3, 3) ... ok
test_nose_tests.test_simple(4, 4) ... ok
test_nose_tests.test_simple(5, 5) ... ok
test_nose_tests.test_complex ... ok
test_nose_tests.test_complex(0, 0) ... ok
test_nose_tests.test_complex(1, 1) ... ok
test_nose_tests.test_complex(2, 2) ... ok
test_nose_tests.test_complex(3, 3) ... ok
test_nose_tests.test_complex(4, 4) ... ok
test_nose_tests.test_complex(5, 5) ... ok
----------------------------------------------------------------------
Ran 13 tests in 0.004s
~/projects/testbox$ pytest -v
==================================================================== test session starts =====================================================================
platform linux2 -- Python 2.7.12, pytest-3.0.6, py-1.4.32, pluggy-0.4.0 -- /usr/bin/python
cachedir: .cache
rootdir: /home/local/ANT/cladam/projects/testbox, inifile:
collected 7 items
tests/test_nose_tests.py::test_simple::[0] PASSED
tests/test_nose_tests.py::test_simple::[1] PASSED
tests/test_nose_tests.py::test_simple::[2] PASSED
tests/test_nose_tests.py::test_simple::[3] PASSED
tests/test_nose_tests.py::test_simple::[4] PASSED
tests/test_nose_tests.py::test_simple::[5] PASSED
tests/test_nose_tests.py::test_complex::[0] PASSED
=================================================================== pytest-warning summary ===================================================================
WC1 /home/local/ANT/cladam/projects/testbox/tests/test_nose_tests.py yield tests are deprecated, and scheduled to be removed in pytest 4.0
....
======================================================== 7 passed, 7 pytest-warnings in 0.01 seconds =========================================================
I am assuming that this is because at collection time the integers list is empty and this it doesn't then collect the 6 additional yield
s.
Is there any way that I can replicate this test structure in pytest
? via pytest_generate_tests
?
This test is representative of a larger sequence of events to build an object up and operate on it, and test at each stage of the process.
- Model something
- validate some model properties
- create and output file based on model
- diff against a known output to see if there are changes.
Thanks in advance