Zorglub29
Zorglub29

Reputation: 8927

pytest run new tests (nearly) first

I am using pytest. I like the way I call pytest (re-try the failed tests first, verbose, grab and show serial output, stop at first failure):

 pytest --failed-first -v -s -x

However there is one more thing I want:

I want pytest to run the new tests (ie tests never tested before) immediately after the --failed-first ones. This way, when working with tests that are long to perform, I would get most relevant information as soon as possible.

Any way to do that?

Upvotes: 2

Views: 679

Answers (2)

Franey
Franey

Reputation: 4354

For anyone coming to this now, pytest added a --new-first option to run new tests before all other tests. It can be combined with --failed-first to run new and failed tests. For test-driven development, I've found it helpful to use these options with pytest-watch, which I described in my blog.

Upvotes: 2

alecxe
alecxe

Reputation: 474171

This may not be directly what you are asking about, but, my understanding is that the test execution order is important for you when you create new tests during development.

Since you are already working with these "new" tests, the pytest-ordering plugin might be a good option to consider. It allows you to influence the execution order by decorating your tests with @pytest.mark.first, @pytest.mark.second etc decorators.


pytest-ordering is able to change the execution order by using a pytest_collection_modifyitems hook. There is also pytest-random-order plugin which also uses the same hook to control/change the order.

You can also have your own hook defined and adjusted to your specific needs. For example, here another hook is used to shuffle the tests:

Upvotes: 3

Related Questions