简体   繁体   中英

Pytest not collecting tests in dependency order

I'm using pytest to test my package and I'm facing problems with dependency of tests, cause pytest is collecting (and testing) the sequence in alphabetical order, while it should be in dependency order. How can I change it?

More details:

The sequence of test it should runis:

  1. materials : Needs nothing
  2. onerodtraction , onerodtorsion , onerodbending : Needs (1)
  3. onerodallcharges : Needs the three above (2)
  4. examples : Needs the (3)

When I run I receive:

tests\test_examples.py ssssssssssss                                                         [ 22%]
tests\test_material.py ...                                                                  [ 27%]
tests\test_onerodallcharges.py sss                                                          [ 33%]
tests\test_onerodbending.py ..................                                              [ 66%]
tests\test_onerodtorsion.py .........                                                       [ 83%]
tests\test_onerodtraction.py .........                                                      [100%]

As we see, every test in the third file is skipped, and then the same happens for the first file.

May be you can try this pytest_order

pip install pytest-order

After installing you can mark on your classes.

https://pytest-dev.github.io/pytest-order/stable/usage.html#markers-on-class-level

In the each python file on each class specify the order as said

@pytest.mark.order(1)
class test_onerodtraction:

@pytest.mark.order(1)
class test_onerodtorsion:

@pytest.mark.order(1)
class test_onerodbending:

and now

@pytest.mark.order(2)
class test_onerodallcharges:

and then

@pytest.mark.order(3)
class test_examples.py:

I would recommend using pytest-dependency

  • With order if you want to add a test case in middle, reordering will be required.
  • parallel execution wont be effective.

https://pytest-dependency.readthedocs.io/en/stable/usage.html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM