question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Add flag which makes pytest to return 0 exit code if no test functions were executed.

See original GitHub issue

Followup from https://github.com/pytest-dev/pytest/issues/812#issuecomment-517869154 and I’m aware about discussion in https://github.com/pytest-dev/pytest/issues/500 .

  • a detailed description of the bug or suggestion

Title. With this flag added calling pytest --the-flag will return 0 exit code if no test function were found.

There are 2 cases to consider:

  • there is no test functions in directory,
  • all tests were deselected.

I only care about the 1st scenario because my use case it to configure CI with tox where testing is one of build steps and I want to have that step in place even if there are no tests yet. Without this flag I would have to do something (e.g. add - pytest in tox.ini) and redo that after some tests were added or perform additional bash scripting which would analyze the test directory and returned code and possibly change the return code accordingly.

Also given that people from other testing tools e.g. unittest are used to scenario “if there is no tests there is no reason to fail” so this flag will give everyone an option about how pytest should behave.

The 2nd mentioned scenario can also have such option but on one side you want to treat “all tests were deselected” as a way to prevent errors. On the other side, why don’t give users an option to configure pytest to their needs? Both, being arbitrary or open for options, have good reasons so it’s hard for me to decide on that one.

Furthermore there may come a question “if you can configure this return code then why shouldn’t it be possible to configure all of them?”. I only want to mention this because it is an extention to this issue and probably requires a separate feature request.

  • pytest and operating system versions

pytest=5.0.1 OS=Arch Linux (Linux-5.2.2-arch1-1-ARCH-x86_64-with-glibc2.2.5)

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:7 (6 by maintainers)

github_iconTop GitHub Comments

2reactions
nicoddemuscommented, Aug 3, 2019

Hah, in fact such a plugin already exists:

https://github.com/yashtodi94/pytest-custom_exit_code

0reactions
yashtodi94commented, Aug 4, 2019

An earlier discussion on this issue just for reference: pytest/issues#2393

Read more comments on GitHub >

github_iconTop Results From Across the Web

Usage and Invocations — pytest documentation
Possible exit codes¶. Running pytest can result in six different exit codes: Exit code 0. All tests were collected and passed successfully. Exit...
Read more >
How to use skip and xfail to deal with tests that cannot succeed
A skip means that you expect your test to pass only if some conditions are met, otherwise pytest should skip running the test...
Read more >
Usage and Invocations — pytest documentation
Exit code 0 : All tests were collected and passed successfully. Exit code 1: Tests were collected and run but some of the...
Read more >
Exit codes — pytest documentation
Running pytest can result in six different exit codes: Exit code 0. All tests were collected and passed successfully. Exit code 1. Tests...
Read more >
Basic patterns and examples — pytest documentation
Pass different values to a test function, depending on command line options¶ ... If one step fails it makes no sense to execute...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found