nose
我正在尝试从to迁移一堆测试,pytest
但在迁移一个验证整个过程的测试时遇到了麻烦。
我把它简化为代表我的问题:
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
nose
在和之间运行良好pytest
,但test_complex
只运行初始update_integers
测试:
~/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 =========================================================
我假设这是因为在收集时整数列表为空,因此它不会收集额外的 6 个yield
s。
有什么方法可以复制这个测试结构pytest
吗?通过pytest_generate_tests
?
这个测试代表了一个更大的事件序列来构建一个对象并对其进行操作,并在过程的每个阶段进行测试。
- 建模一些东西
- 验证一些模型属性
- 基于模型创建和输出文件
- 比较已知输出以查看是否有更改。
提前致谢