Test case execution order in pytest

前端 未结 7 1834
情书的邮戳
情书的邮戳 2020-11-28 12:01

I am using pytest. I have two files in a directory. In one of the files there is a long running test case that generates some output. In the other file there is a test case

7条回答
  •  春和景丽
    2020-11-28 12:25

    In general you can configure the behavior of basically any part of pytest using its well-specified hooks.

    In your case, you want the "pytest_collection_modifyitems" hook, which lets you re-order collected tests in place.

    That said, it does seem like ordering your tests should be easier -- this is Python after all! So I wrote a plugin for ordering tests: "pytest-ordering". Check out the docs or install it from pypi. Right now I recommend using @pytest.mark.first and @pytest.mark.second, or one of the @pytest.mark.order# markers, but I have some ideas about more useful APIs. Suggestions welcome :)

提交回复
热议问题