Skip to content

Instantly share code, notes, and snippets.

@tjkhara
Created October 18, 2020 16:12
Show Gist options
  • Select an option

  • Save tjkhara/d057270f7c95ddcdaed7038dabbcc92b to your computer and use it in GitHub Desktop.

Select an option

Save tjkhara/d057270f7c95ddcdaed7038dabbcc92b to your computer and use it in GitHub Desktop.
PyTest Setup and Teardown in class
class TestClass:
@classmethod
def setup_class(cls):
print("Setup Testclass")
@classmethod
def teardown_class(cls):
print("Teardown class")
def setup_method(self, method):
if method == self.test1:
print("\nSetting up test 1")
elif method == self.test2:
print("\nSetting up test 2")
else:
print("\nSetting up unknown test")
def teardown_method(self, method):
if method == self.test1:
print("\n Tearing down test 1")
elif method == self.test2:
print("\n Tearing down test 2")
else:
print("\nTearing down unknown test")
def test1(self):
print("Executing test 1")
assert True
def test2(self):
print("Executing test 2")
assert True
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment