-
I want to run tests by calling pytest like this: tests = ['path\testfile.py::test_init','path\testfile.py::test1','path\testfile.py::test2','path\testfile.py::test_deinit',
'path\testfile.py::test_init','path\testfile.py::test3','path\testfile.py::test4','path\testfile.py::test_deinit']
pytest.main(tests) How many tests are defined within init and deinit is up to the tester to define in the testsfile.py(if necesary I can explain this logic), My question is: Pytest only runs the test_init and test_deinit only once and for the second line on the command both are not runned, so current pytest output on the log is for example like this: tests collected: 8
The output I wish to accomplish is:
This tests control some hardware so init and deinit has to be made to prepare test preconditions. |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 2 replies
-
searchig for answers I found this post https://stackoverflow.com/questions/46387285/pytest-3-2-2-duplicate-test, but in my case Im not redefining the test_init or test_deinit, I just want to run them again, so the --keep-duplicates has no effect for me. |
Beta Was this translation helpful? Give feedback.
-
That's what fixture scopes and parameterization is for, reinventing them in a call like that isn't going to cut it |
Beta Was this translation helpful? Give feedback.
-
the pure pytest solution was to add fixtures to the tests on the input arguments, and no longer use/passed init and deinit as tests as on my post above: @pytest.fixture
def init_system():
print("This is init_system")
@pytest.fixture
def deinit_system():
yield
print("this is deinit_system ") I have explain how I added the fixtureas after test collection on this post: https://stackoverflow.com/questions/76079122/run-a-test-more-than-onces-with-pytest-main/76140534#76140534 |
Beta Was this translation helpful? Give feedback.
the pure pytest solution was to add fixtures to the tests on the input arguments, and no longer use/passed init and deinit as tests as on my post above:
I have explain how I added the fixtureas after test collection on this post: https://stackoverflow.com/questions/76079122/run-a-test-more-than-onces-with-pytest-main/76140534#76140534