What is the (intended) way to do plugin based clean up, config._cleanup.append(func) vs pytest_unconfigure? #7992
-
Hi, There seems to be two similar mechanisms surrounding post-session and general cleanup. Which is the preferred method for plugin related clean up, outlined below is some sudo code: # Option 1
def pytest_configure(config) -> None:
# do something if some condition is true, something I need undone
# Optional append a cleanup function to the config._cleanup directly.
# (this will be popped and invoked post-session later on). # Option 2
def pytest_configure(config) -> None:
# do something if some condition is true, something I need undone
def pytest_unconfigure(config) -> None:
# undo the thing myself here. both are handled by the Question: When (working as a contributor) should we be loading things into the config._cleanup vs having the core plugin register its own unconfigure hook ? (third party users of pytest I assume should never be doing this as its private and possible to change? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
we currently have no clear guide for that, and the api currently is not that nice ideally configure/unconfigure turns into something that gets recorded in the "setupstate" but that refactoring has neither been discussed, nor explored yet currently in core, using the cleanup is acceptable, plugins have to bite it and use configure/unconfigure |
Beta Was this translation helpful? Give feedback.
we currently have no clear guide for that, and the api currently is not that nice
ideally configure/unconfigure turns into something that gets recorded in the "setupstate" but that refactoring has neither been discussed, nor explored yet
currently in core, using the cleanup is acceptable, plugins have to bite it and use configure/unconfigure