Created
October 18, 2020 16:12
-
-
Save tjkhara/d057270f7c95ddcdaed7038dabbcc92b to your computer and use it in GitHub Desktop.
PyTest Setup and Teardown in class
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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