Skip to content

Instantly share code, notes, and snippets.

@matthewshirley
Created March 30, 2021 23:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save matthewshirley/4fa6ac86f8454553fe25363907cb8156 to your computer and use it in GitHub Desktop.
Save matthewshirley/4fa6ac86f8454553fe25363907cb8156 to your computer and use it in GitHub Desktop.
pytest post-setup hook for unittest
@pytest.hookimpl(hookwrapper=True)
def pytest_runtest_call(item):
instance = item._obj
self = instance.__self__
if getattr(self, 'post_setup', False):
def setUpWithHooks():
self.originalSetUp()
self.post_setup()
self.originalSetUp = self.setUp
self.setUp = setUpWithHooks
item.runtest()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment