So I have a directory filled with a bunch of tests written in python with the proper syntax to make sure they run in order.
So let's say I have a test which if fails, currently calls pytest.exit('Exit Message'). The problem with this is that the generated test output in XML only records the tests preceding it. I would prefer that the whole suite is run but are reported as failed if the test mentioned above fails.
A solution I thought of was setting an environment variable in case it fails and then checking that environment variable in the following tests. The issue is that running it with Jenkins, the environment variable set isn't detected and I would prefer a native solution if it exists.
What I have is:
def test_check_connection(self):
...
if Failed:
pytest.exit('No connectivity')
PyTest offers a command-line option called maxfail which is used to stop test suite after n test failures.
The plugin provides two command line options to rerun failures from the last pytest invocation: --lf , --last-failed - to only re-run the failures. --ff , --failed-first - to run the failures first and then the rest of the tests.
Running pytest We can run a specific test file by giving its name as an argument. A specific function can be run by providing its name after the :: characters. Markers can be used to group tests. A marked grouped of tests is then run with pytest -m .
Debug failed testsGo to Build, Execution, Deployment | Python Debugger and select the Drop into debugger on failed tests checkbox.
I'm not sure I understand your problem correctly. If you want pytest
to stop after the first failing test case use the -x
option
pytest -x ...
If you want to run all tests and want to know if there were any failures from jenkins check the exit code of the pytest app:
Running pytest can result in six different exit codes:
Exit code 0: All tests were collected and passed successfully
Exit code 1: Tests were collected and run but some of the tests failed
Exit code 2: Test execution was interrupted by the user
Exit code 3: Internal error happened while executing tests
Exit code 4: pytest command line usage error
Exit code 5: No tests were collected
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With