-
Notifications
You must be signed in to change notification settings - Fork 23
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
Discussion about how subtests failures should be displayed #11
Comments
(Continuing the discussion here because the verbosity problem that started the discussion in #7 has been fixed).
Behind the scenes, what happens is:
This is the same behavior we see with import unittest
class T(unittest.TestCase):
def test_fail(self):
with self.subTest():
self.assertEqual(1, 2)
self.assertEqual(1, 2)
if __name__ == '__main__':
unittest.main() We get:
So we have: 1 sub-test failure, and 1 normal failure. This is better seen here because we clearly see the failure context for the subtest ( We don't see 2 passes because
So "passes" don't get special reporting, but behind the scenes the main test still passed, even if the subtest failed (they are two separate reports, just as with the As we have discussed in #7 (comment), perhaps after we have improved the output to get this:
Things won't be so confusing anymore? To achieve this I will need further changes in pytest though (pytest-dev/pytest#5047). |
Well, that's definitely more clear and makes subtests more usable and less surprising. |
Unfortunately, I think there's a lot here that needs untangling, some of which derives from (IMO undesirable) idiosyncrasy of For these, MAIN BODY PASS means that there either were no asserts in the main function body, or all asserts there passed; MAIN BODY FAIL means a failing assert was present in the main body.
Stuff used to figure out the above pytest config:
Contents of
unittest execution:
pytest execution of just the unittest-style tests:
pytest execution of just the pytest-style tests:
|
Separately from the above reporting and unittest-compat logistics, I would like having the ability to switch on a mode where any failing subtest causes the encapsulating test also to fail. This IMO would greatly improve using xfails with subtests, because then I wouldn't have to care which subtest failed to trigger the xfail. Alternatively (and/or additionally), it would be nice to have an |
(I'm short on time so I will read your post more carefully later @bskinn, thanks!)
Just wanted to mention that |
🤦♂️ Thank you. 😃 |
Sorry for bumping an old issue, but I believe that there is one more factor that was not considered: currently subtests do not fail the whole test, breaking |
One more test case that is interesting.
This file:
No passing subtests, just one failure. Still shows PASSED.
I would expect FAILED and the bottom line to show
1 failed
Maybe pytest itself is calling
pytest_runtest_logreport()
at the end and causing an extra test to be counted.Originally posted by @okken in #7 (comment)
cc @jurisbu @bskinn
The text was updated successfully, but these errors were encountered: