简体   繁体   English

Pytest 未按依赖顺序收集测试

[英]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.我正在使用pytest来测试我的 package 并且我遇到了测试依赖性问题,因为pytest正在收集(和测试)它应该按字母顺序排列。 How can I change it?我怎样才能改变它?

More details:更多细节:

The sequence of test it should runis:它应该运行的测试顺序是:

  1. materials : Needs nothing materials :什么都不需要
  2. onerodtraction , onerodtorsion , onerodbending : Needs (1) onerodtraction , onerodtorsion , onerodbending : 需要 (1)
  3. onerodallcharges : Needs the three above (2) onerodallcharges : 需要以上三个(2)
  4. examples : Needs the (3) examples :需要 (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也许你可以试试这个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 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在每个 class 上的每个 python 文件中指定所述顺序

@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我建议使用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 https://pytest-dependency.readthedocs.io/en/stable/usage.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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