-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
How to intercept setup_module and setup_class when it fails from own plugin file #3378
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
Comments
Unfortunately I don't think this is currently possible, |
@nicoddemus : Ok, got that. However, is there a way when a test case goes into an 'ERROR' state, we can determine was it because of setup_module() failure or setup_class() failure. Anywhere in pytest_exception_interact() hook or other item hook we can determine this? I hv seen for a node, node.session.exitstatus=0 when setup_module() fails or setup_class() fails. But, can't tell from this exit status that who failed- setup_module() or setup_class() |
It might be possible to write a hook wrapper around Can you describe what you are trying to accomplish? Perhaps by understanding your use case we might suggest alternatives. Also have you considered switching to fixtures? That would make things much easier to deal with. |
Ok.So what I am trying to do is invoke our own debug infra whenever an exception is encountered, wherever that exception is coming from - be it from setup_module(), setup_class or from the test case itself. In current scenario, I have implemented pytest_exception_interact() hook where is check for report.outcome==failed and process the call.excinfo for further debug infra stuff. Now assume setup_module() fails, then all the test cases (say I have 50 tests) inside that script will land up in pytest_exception_interact() hook because all these test's report.outcome is = failed. I don't want to execute the code in pytest_exception_interact() hook 50 times because it adds to my run time and its obvious that all these 50 tests are going to be in "ERROR" state, but executing the code in pytest_exception_interact() is redundant. |
I see @shreyashah thanks for the clarification. Unfortunately I'm not sure it is possible to know if the failure at the point where |
@RonnyPfannschmidt do you have any pointers here perhaps? |
other than walking the stack, nope |
What if we passed the EDIT: |
Afair We don't have those there |
Yeah we would need some refactor to access the |
If a setup_module() fails, then the error is propagated to all the test cases and all those test cases go into 'ERROR' state showing the same propagated error. This is understood.
However, I want to intercept using a hook or a method when setup_module() fails. I tried pytest_exception_interact() hook, but that seems to come into picture if a test case fails/errors.
How do I intercept in my plugin file when setup_module() fails to execute some custom things?
Similarly, how do I iintercept when setup_class fails?
The text was updated successfully, but these errors were encountered: