-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Option to suppress exit code 5 (no tests run) #2393
Comments
FWIW you can do something like def test_placeholder():
pass |
im closing this, as the very reason for having and not suppressing this error code is to learn of broken/gone bad ci setups, its just as easy to simply put a first green test you know you will fill out later than to opt out of something you may forget about |
Thanks for the suggestion @jakirkham, but I agree with @RonnyPfannschmidt that we shouldn't add yet another option to pytest to handle this case specially because an alternative solution is trivial and easy to do, while the possible drawbacks can be a pain (forgetting later that the option is set like @RonnyPfannschmidt mentioned). |
But what in case the
where tox -e all -- -m smoketest
Any idea how to substitute this use case? |
@mkleina I am using the following #!/bin/sh
pytest "$@"
ret=$?
if [ "$ret" = 5 ]; then
echo "No tests collected. Exiting with 0 (instead of 5)."
exit 0
fi
exit "$ret" |
we ought to have a pytest plugin to do that for people that truely need it (since a shell wrapper is pretty anti-portable |
Agree with the plugin idea, should be simple to do. |
Any news? |
@ChiKenNeg nobody worked on a plugin for this as far as i know, if you'd like to have one, i strongly suggest making one |
A little hack. But something on these lines should work fine. ( Add this to your conftest.py:
|
@yashtodi94 would you be willing to create a plugin with that solution? |
Sure...I'll try submitting a PR by next week |
@yashtodi94 I think implementing the plugin in a different repository and linking it here is the norm, because it isn't changing pytest directly. |
Yes, I discovered that after posting my previous comment. Thanks for the help :) |
First attempt at building a plugin: https://pypi.org/project/pytest-custom-exit-code/ |
Awsome @yashtodi94, thanks for sharing! 🙃 |
Fix broken notebook tests in master. It seems that when `pattern` does not match any tests in `pytest -k pattern`, pytest returns an exit code 5. This breaks the newly sharded notebook tests, which are leveraging the `-k partition-n` pattern for changed notebooks. This fix adds the fix as per the recommendations of pytest-dev/pytest#2393.
Our nightly container builds are failing, because all the integration tests are skipped (since we don't have faiss/feast on the containers). pytest returns error code '5' in this case, causing us to fail the container. Use the workaround as suggested pytest-dev/pytest#2393 (comment)
Our nightly container builds are failing, because all the integration tests are skipped (since we don't have faiss/feast on the containers). pytest returns error code '5' in this case, causing us to fail the container. Use the workaround as suggested pytest-dev/pytest#2393 (comment)
I made a variation of that because sometimes the re-run had zero tests and exited with code 5. Thanks for posting it.
|
Also, here is an example of how to have a workaround for this in a .PHONY: test
test:
sh -c 'poetry run pytest **.py || ([ $$? = 5 ] && exit 0 || exit $$?)' |
I guess this works for me, would have been nice if pytest just had an option for it though |
I just ran into this issue today attempting to amend a commit in which all I did was remove a few |
Fix broken notebook tests in master. It seems that when `pattern` does not match any tests in `pytest -k pattern`, pytest returns an exit code 5. This breaks the newly sharded notebook tests, which are leveraging the `-k partition-n` pattern for changed notebooks. This fix adds the fix as per the recommendations of pytest-dev/pytest#2393.
I modified @yashtodi94 's solution a bit to only swallow the failure if I passed the
|
- 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
- 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
- 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
…re in Python testing script ### What changes were proposed in this pull request? This PR proposes to avoid treating the exit code 5 as a test failure in Python testing script. ### Why are the changes needed? ``` ... ======================================================================== Running PySpark tests ======================================================================== Running PySpark tests. Output is in /__w/spark/spark/python/unit-tests.log Will test against the following Python executables: ['python3.12'] Will test the following Python modules: ['pyspark-core', 'pyspark-streaming', 'pyspark-errors'] python3.12 python_implementation is CPython python3.12 version is: Python 3.12.1 Starting test(python3.12): pyspark.streaming.tests.test_context (temp output: /__w/spark/spark/python/target/8674ed86-36bd-47d1-863b-abb0405557f6/python3.12__pyspark.streaming.tests.test_context__umu69c3v.log) Finished test(python3.12): pyspark.streaming.tests.test_context (12s) Starting test(python3.12): pyspark.streaming.tests.test_dstream (temp output: /__w/spark/spark/python/target/847eb56b-3c5f-49ab-8a83-3326bb96bc5d/python3.12__pyspark.streaming.tests.test_dstream__rorhk0lc.log) Finished test(python3.12): pyspark.streaming.tests.test_dstream (102s) Starting test(python3.12): pyspark.streaming.tests.test_kinesis (temp output: /__w/spark/spark/python/target/78f23c83-c24d-4fa1-abbd-edb90f48dff1/python3.12__pyspark.streaming.tests.test_kinesis__q5l1pv0h.log) test_kinesis_stream (pyspark.streaming.tests.test_kinesis.KinesisStreamTests.test_kinesis_stream) ... skipped "Skipping all Kinesis Python tests as environmental variable 'ENABLE_KINESIS_TESTS' was not set." test_kinesis_stream_api (pyspark.streaming.tests.test_kinesis.KinesisStreamTests.test_kinesis_stream_api) ... skipped "Skipping all Kinesis Python tests as environmental variable 'ENABLE_KINESIS_TESTS' was not set." ---------------------------------------------------------------------- Ran 0 tests in 0.000s NO TESTS RAN (skipped=2) Had test failures in pyspark.streaming.tests.test_kinesis with python3.12; see logs. Error: running /__w/spark/spark/python/run-tests --modules=pyspark-core,pyspark-streaming,pyspark-errors --parallelism=1 --python-executables=python3.12 ; received return code 255 Error: Process completed with exit code 19. ``` Scheduled job fails because of exit 5, see pytest-dev/pytest#2393. This isn't a test failure. ### Does this PR introduce _any_ user-facing change? No, test-only. ### How was this patch tested? Manually tested. ### Was this patch authored or co-authored using generative AI tooling? No, Closes #44841 from HyukjinKwon/SPARK-46801. Authored-by: Hyukjin Kwon <[email protected]> Signed-off-by: Dongjoon Hyun <[email protected]>
…re in Python testing script ### What changes were proposed in this pull request? This PR proposes to avoid treating the exit code 5 as a test failure in Python testing script. ### Why are the changes needed? ``` ... ======================================================================== Running PySpark tests ======================================================================== Running PySpark tests. Output is in /__w/spark/spark/python/unit-tests.log Will test against the following Python executables: ['python3.12'] Will test the following Python modules: ['pyspark-core', 'pyspark-streaming', 'pyspark-errors'] python3.12 python_implementation is CPython python3.12 version is: Python 3.12.1 Starting test(python3.12): pyspark.streaming.tests.test_context (temp output: /__w/spark/spark/python/target/8674ed86-36bd-47d1-863b-abb0405557f6/python3.12__pyspark.streaming.tests.test_context__umu69c3v.log) Finished test(python3.12): pyspark.streaming.tests.test_context (12s) Starting test(python3.12): pyspark.streaming.tests.test_dstream (temp output: /__w/spark/spark/python/target/847eb56b-3c5f-49ab-8a83-3326bb96bc5d/python3.12__pyspark.streaming.tests.test_dstream__rorhk0lc.log) Finished test(python3.12): pyspark.streaming.tests.test_dstream (102s) Starting test(python3.12): pyspark.streaming.tests.test_kinesis (temp output: /__w/spark/spark/python/target/78f23c83-c24d-4fa1-abbd-edb90f48dff1/python3.12__pyspark.streaming.tests.test_kinesis__q5l1pv0h.log) test_kinesis_stream (pyspark.streaming.tests.test_kinesis.KinesisStreamTests.test_kinesis_stream) ... skipped "Skipping all Kinesis Python tests as environmental variable 'ENABLE_KINESIS_TESTS' was not set." test_kinesis_stream_api (pyspark.streaming.tests.test_kinesis.KinesisStreamTests.test_kinesis_stream_api) ... skipped "Skipping all Kinesis Python tests as environmental variable 'ENABLE_KINESIS_TESTS' was not set." ---------------------------------------------------------------------- Ran 0 tests in 0.000s NO TESTS RAN (skipped=2) Had test failures in pyspark.streaming.tests.test_kinesis with python3.12; see logs. Error: running /__w/spark/spark/python/run-tests --modules=pyspark-core,pyspark-streaming,pyspark-errors --parallelism=1 --python-executables=python3.12 ; received return code 255 Error: Process completed with exit code 19. ``` Scheduled job fails because of exit 5, see pytest-dev/pytest#2393. This isn't a test failure. ### Does this PR introduce _any_ user-facing change? No, test-only. ### How was this patch tested? Manually tested. ### Was this patch authored or co-authored using generative AI tooling? No, Closes #44841 from HyukjinKwon/SPARK-46801. Authored-by: Hyukjin Kwon <[email protected]> Signed-off-by: Dongjoon Hyun <[email protected]> (cherry picked from commit 52b6292) Signed-off-by: Dongjoon Hyun <[email protected]>
…re in Python testing script ### What changes were proposed in this pull request? This PR proposes to avoid treating the exit code 5 as a test failure in Python testing script. ### Why are the changes needed? ``` ... ======================================================================== Running PySpark tests ======================================================================== Running PySpark tests. Output is in /__w/spark/spark/python/unit-tests.log Will test against the following Python executables: ['python3.12'] Will test the following Python modules: ['pyspark-core', 'pyspark-streaming', 'pyspark-errors'] python3.12 python_implementation is CPython python3.12 version is: Python 3.12.1 Starting test(python3.12): pyspark.streaming.tests.test_context (temp output: /__w/spark/spark/python/target/8674ed86-36bd-47d1-863b-abb0405557f6/python3.12__pyspark.streaming.tests.test_context__umu69c3v.log) Finished test(python3.12): pyspark.streaming.tests.test_context (12s) Starting test(python3.12): pyspark.streaming.tests.test_dstream (temp output: /__w/spark/spark/python/target/847eb56b-3c5f-49ab-8a83-3326bb96bc5d/python3.12__pyspark.streaming.tests.test_dstream__rorhk0lc.log) Finished test(python3.12): pyspark.streaming.tests.test_dstream (102s) Starting test(python3.12): pyspark.streaming.tests.test_kinesis (temp output: /__w/spark/spark/python/target/78f23c83-c24d-4fa1-abbd-edb90f48dff1/python3.12__pyspark.streaming.tests.test_kinesis__q5l1pv0h.log) test_kinesis_stream (pyspark.streaming.tests.test_kinesis.KinesisStreamTests.test_kinesis_stream) ... skipped "Skipping all Kinesis Python tests as environmental variable 'ENABLE_KINESIS_TESTS' was not set." test_kinesis_stream_api (pyspark.streaming.tests.test_kinesis.KinesisStreamTests.test_kinesis_stream_api) ... skipped "Skipping all Kinesis Python tests as environmental variable 'ENABLE_KINESIS_TESTS' was not set." ---------------------------------------------------------------------- Ran 0 tests in 0.000s NO TESTS RAN (skipped=2) Had test failures in pyspark.streaming.tests.test_kinesis with python3.12; see logs. Error: running /__w/spark/spark/python/run-tests --modules=pyspark-core,pyspark-streaming,pyspark-errors --parallelism=1 --python-executables=python3.12 ; received return code 255 Error: Process completed with exit code 19. ``` Scheduled job fails because of exit 5, see pytest-dev/pytest#2393. This isn't a test failure. ### Does this PR introduce _any_ user-facing change? No, test-only. ### How was this patch tested? Manually tested. ### Was this patch authored or co-authored using generative AI tooling? No, Closes #44841 from HyukjinKwon/SPARK-46801. Authored-by: Hyukjin Kwon <[email protected]> Signed-off-by: Dongjoon Hyun <[email protected]> (cherry picked from commit 52b6292) Signed-off-by: Dongjoon Hyun <[email protected]>
…re in Python testing script ### What changes were proposed in this pull request? This PR proposes to avoid treating the exit code 5 as a test failure in Python testing script. ### Why are the changes needed? ``` ... ======================================================================== Running PySpark tests ======================================================================== Running PySpark tests. Output is in /__w/spark/spark/python/unit-tests.log Will test against the following Python executables: ['python3.12'] Will test the following Python modules: ['pyspark-core', 'pyspark-streaming', 'pyspark-errors'] python3.12 python_implementation is CPython python3.12 version is: Python 3.12.1 Starting test(python3.12): pyspark.streaming.tests.test_context (temp output: /__w/spark/spark/python/target/8674ed86-36bd-47d1-863b-abb0405557f6/python3.12__pyspark.streaming.tests.test_context__umu69c3v.log) Finished test(python3.12): pyspark.streaming.tests.test_context (12s) Starting test(python3.12): pyspark.streaming.tests.test_dstream (temp output: /__w/spark/spark/python/target/847eb56b-3c5f-49ab-8a83-3326bb96bc5d/python3.12__pyspark.streaming.tests.test_dstream__rorhk0lc.log) Finished test(python3.12): pyspark.streaming.tests.test_dstream (102s) Starting test(python3.12): pyspark.streaming.tests.test_kinesis (temp output: /__w/spark/spark/python/target/78f23c83-c24d-4fa1-abbd-edb90f48dff1/python3.12__pyspark.streaming.tests.test_kinesis__q5l1pv0h.log) test_kinesis_stream (pyspark.streaming.tests.test_kinesis.KinesisStreamTests.test_kinesis_stream) ... skipped "Skipping all Kinesis Python tests as environmental variable 'ENABLE_KINESIS_TESTS' was not set." test_kinesis_stream_api (pyspark.streaming.tests.test_kinesis.KinesisStreamTests.test_kinesis_stream_api) ... skipped "Skipping all Kinesis Python tests as environmental variable 'ENABLE_KINESIS_TESTS' was not set." ---------------------------------------------------------------------- Ran 0 tests in 0.000s NO TESTS RAN (skipped=2) Had test failures in pyspark.streaming.tests.test_kinesis with python3.12; see logs. Error: running /__w/spark/spark/python/run-tests --modules=pyspark-core,pyspark-streaming,pyspark-errors --parallelism=1 --python-executables=python3.12 ; received return code 255 Error: Process completed with exit code 19. ``` Scheduled job fails because of exit 5, see pytest-dev/pytest#2393. This isn't a test failure. ### Does this PR introduce _any_ user-facing change? No, test-only. ### How was this patch tested? Manually tested. ### Was this patch authored or co-authored using generative AI tooling? No, Closes apache#44841 from HyukjinKwon/SPARK-46801. Authored-by: Hyukjin Kwon <[email protected]> Signed-off-by: Dongjoon Hyun <[email protected]> (cherry picked from commit 52b6292) Signed-off-by: Dongjoon Hyun <[email protected]>
For information, I ran into this issue today while running |
For the most part, I think the addition of PR ( #817 ) to have a special exit code to denote no tests run was a good idea. However when I start out a project, I may not have any tests as there is no real code. Still I would like to get everything up and running (i.e. CIs). It would be nice in these cases like this to have an option to suppress this behavior and have exit code 0 returned instead.
The text was updated successfully, but these errors were encountered: