Reputation: 760
I've created a test class generator:
import pytest
def t_1(self):
print("1")
assert True
def t_2(self):
print("2")
assert True
def t_3(self):
print("3")
assert True
new_cls = type("TestClass", (),
{
"test_1": t_1,
"test_0": t_2,
"test_2": t_3
})
TestClass = new_cls
The output (python3 -m pytest -s test.py
) is:
1
2
3
My question: in these scenarios, how is the ordering of the tests determined? For example, if my functions I'm using are defined in other modules (or in functions), how do I know in what order these tests will execute?
Upvotes: 1
Views: 236
Reputation: 35
First, your packages are sorted in alphabetical order, then test modules, test classes and finally test functions.
I'd recommend avoiding using dependent tests as it may cause certain issues.
If you want to apply your own ordering, try "pytest_collection_modifyitems" hook or some plugins like "pytest-ordering".
Upvotes: 2