Skip to content

Commit

Permalink
If no tests then Pytest should exit with 0 (not 5)
Browse files Browse the repository at this point in the history
- Add a 'test' target to run pytest against the 'tests' directory. If an
  exit code of 5 is found then exit with a 0 instead. Otherwise exit
  with the appropriate error code.

- Intercept 'pytest_sessionfinish' to do the same thing in conftest.py
  [1].

- Switch off 'disallowed_untyped_defs' in mypy.ini as hints should help
  readability where it makes sense (hence 'hints'). It should not be enforced
  all the time IMHO.

[1] pytest-dev/pytest#2393
  • Loading branch information
webventurer committed Jan 13, 2024
1 parent bb71ce0 commit e07d756
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/python-app.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,4 @@ jobs:
- name: Check types
run: make types
- name: Run tests
run: pytest -o console_output_style=classic -v
run: pytest -o console_output_style=classic -v || ([ $? = 5 ] && exit 0 || exit $?)
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,7 @@ format:
.PHONY: types
types:
mypy .

.PHONY: test
test:
sh -c 'pytest tests || ([ $$? = 5 ] && exit 0 || exit $$?)'
2 changes: 1 addition & 1 deletion test
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
set -e

make check
pytest "$@"
make test
7 changes: 7 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
NO_TESTS_COLLECTED = 5
SUCCESS = 0


def pytest_sessionfinish(session, exitstatus):
if exitstatus == NO_TESTS_COLLECTED and session.config.getoption("-k"):
session.exitstatus = SUCCESS

0 comments on commit e07d756

Please sign in to comment.