Repository navigation
Replies: 2 comments 1 reply
|
This is intended, otherwise every single fixture would need to handle a failing test manually somehow. You could probably do something clever with hooks, but what I'd do in your case is just printing the information either way - pytest's capturing will only show it for failing tests by default. |
1 reply
|
OK, thanks for the quick reply! I see the difficulty that some fixtures would want this behavior and others wouldn't. @The-Compiler Yes, I think printing the info either way is the most expedient solution for my case. If the current behavior isn't mentioned in the docs somewhere, it probably should be! It was a bit of a surprise to me that my context manager's error handler wasn't being invoked. |
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
I have a pytest fixture, written in "yield fixture" style, that wants to observe a test failure in order to do extra reporting.
In particular, my fixture is setting up a temporary directory, and if there's a failure in the test, I want it to print the contents of that directory so I can see more of what was and wasn't created in there during the test.
But it seems like exceptions get swallowed before coming out of the "yield" of a yield-style fixture; is that right? I see this old bug thread that suggests so: #2508 But I don't see anything corroborating that in the current docs https://docs.pytest.org/en/stable/how-to/fixtures.html so I wasn't sure.
It's a pity because in fact I'm using a context manager defined elsewhere, that doesn't know it's in a test. My fixture looks like this:
So that "temporary filesystem" helper, which is what tries to catch, print something, and rethrow the exception, is not wise to the fact that it's inside a pytest fixture, and it would be a pity to rewrite it.
Is it really not possible to pass the exception to the fixture?
All reactions