0

I am using python unit test framework to run automated test cases. Currently I want to have the ability to fail the test suite if a condition is not met even if all the test cases pass. I want the test suite to fail because I want my CI server to report a bad build so user's know to investigate why the condition failed. Is there a way to do this elegantly using the unit test framework?

tyleax
  • 1,556
  • 2
  • 17
  • 45
  • Just write another test that checks for whatever condition you would like to trigger the failure? – larsks Jul 12 '23 at 22:12
  • I did consider this but it's a bit hacky as this test were need to be "forced" to run at the end. Also this test isn't testing the application features but checking for leaks after problem close once the test suite is finished. – tyleax Jul 12 '23 at 22:13
  • Might need more detail or code example but based on what you have described maybe using 'mark' in pytest. If you are checking for some environment variable you could write a test that says `assert os.environ['var'] = 'x'` and mark that test as 'CI' so it only runs during CI. You can control that by passing a flag e.g. `--cli`. You can control marking and flagging with pytest. See examples here (https://stackoverflow.com/questions/47559524/pytest-how-to-skip-tests-unless-you-declare-an-option-flag) – spo Jul 13 '23 at 00:28

0 Answers0