Skip to content Skip to sidebar Skip to footer

Pytest Running Scenarios In The Correct Order In The Class

So I have the following structure: class Test(object): def test_1(self): pass def test_2(self): pass def test_3(self): pass it runs great, NOW I'm ad

Solution 1:

The upcoming pytest-2.3 has support for better (resource-based) ordering, and i just updated the scenario example in the docs: https://docs.pytest.org/en/latest/example/parametrize.html#a-quick-port-of-testscenarios

You can preliminary install the current development version with

pip install -i http://pypi.testrun.org -U pytest

and should get pytest-2.3.0.dev15 with "py.test --version" and be able to use it.

Solution 2:

py.test runs tests in a distributed fashion, which means the order is essentially random.

You should use the -n option and set the process number to 1. Then tests should be run in alphabetical order by the single process spawned.

More than this I don't know if you can do. Anyway depending on the order of tests is generally bad design. So you should try to not depend on it at all.

Post a Comment for "Pytest Running Scenarios In The Correct Order In The Class"