Perform a teardown immediately after a session scoped setup fixture fails. #12420
Answered
by
EugeneBrod
EugeneBrod
asked this question in
Q&A
-
Hi there. I have 2 session scoped setup fixtures:
I'd like to perform an immediate teardown if the setup fails or if the call fails. The teardown would need the object created from fixture 1.
This approach works well when the failure occurs in the test call. But if the test setup fails, the teardown is deferred. Looking for suggestions. Thanks in advance. |
Beta Was this translation helpful? Give feedback.
Answered by
EugeneBrod
Jun 24, 2024
Replies: 1 comment 1 reply
-
I'd expect this to work off-hand. Could you show a self-contained, complete example, that's formatted correctly so that someone can actually copy and run it? |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Problem
I wanted to create crashlogs immediately after failure in setup or test call. I wanted to generate crashlogs once for every fixture, whether session or function scoped. To generate crashlogs I needed the result of a reliable "base" fixture which is run first during test execution.
Solution
Define a "SessionControlBlock" class, which stores the result of the "base" fixture and a few methods for generating crashlogs. The class is assigned to the pytest's "session" object.
I then implemented the pytest_fixture_setup hook to
The pytest_make_repor…