Replies: 3 comments 6 replies
-
its not clear what you are asking for but it seems like you should use a fixture for your targets or outline the use case enough to avoid the XY-problem |
Beta Was this translation helpful? Give feedback.
-
I found something but it is also a bit hacky but it causes my tests to pass and fulfills the requirements set. Creating a global variable, set it to true when last test and then do the teardown in logfinish hook: conftest
|
Beta Was this translation helpful? Give feedback.
-
I just tested with an autouse fixture recommended by @RonnyPfannschmidt and It is working! but it is still risky as if others then define an autouse fixture. |
Beta Was this translation helpful? Give feedback.
-
Hello,
I am working on fixing a bug in some internal tools we use to handle working with targets in test.
The tool itself interacts with different targets across multiple Python packages and helps user interact with the targets. The tool is a Pytest plugin that between each tests closes the target
Closing the targets works fine with
pytest_runtest_teardown
unless people use the targets in the teardown (which they do).I resolved my issue initially by closing my targets in the
pytest_runtest_setup
but this looks confusing when reading the output of a test so that's not acceptable.So my question is. How does PyTest "close"/exit fixtures and is there a more nicer way for me to do something after fixtures are closed?
I have been reading a bit in
_pytest/fixtures.py
but I could not find anything that could answer my questions.Example of where i need to hook onto:
I have some targets that are fixtures. These fixtures has to be closed before I can then close the connection. This is something that has to be done across many tests that are separated into different repositories and therefore I cannot do it with a fixture.
I made an example of what I need but I am very unsure how helpful it is.
Conftest.
Testcase
Beta Was this translation helpful? Give feedback.
All reactions