From e07d7569fd037ad18565d09a53fd9250ac252cf0 Mon Sep 17 00:00:00 2001 From: Mike Mindel Date: Fri, 12 Jan 2024 18:51:37 +0000 Subject: [PATCH] If no tests then Pytest should exit with 0 (not 5) - 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] https://github.com/pytest-dev/pytest/issues/2393 --- .github/workflows/python-app.yml | 2 +- Makefile | 4 ++++ test | 2 +- tests/conftest.py | 7 +++++++ 4 files changed, 13 insertions(+), 2 deletions(-) diff --git a/.github/workflows/python-app.yml b/.github/workflows/python-app.yml index 8d42183..0685e88 100644 --- a/.github/workflows/python-app.yml +++ b/.github/workflows/python-app.yml @@ -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 $?) diff --git a/Makefile b/Makefile index a822f7c..49c15e3 100644 --- a/Makefile +++ b/Makefile @@ -26,3 +26,7 @@ format: .PHONY: types types: mypy . + +.PHONY: test +test: + sh -c 'pytest tests || ([ $$? = 5 ] && exit 0 || exit $$?)' diff --git a/test b/test index 84ef6d3..b5751f6 100755 --- a/test +++ b/test @@ -3,4 +3,4 @@ set -e make check -pytest "$@" +make test diff --git a/tests/conftest.py b/tests/conftest.py index e69de29..94f963c 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -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