Source From Here
QuestionI need to execute a command after the entire testsuite has run or at the exit of the whole tests. I see tearDown hook in unittest but there is no after-testsuite hook or something like atexit module.
Is there any approach in unittest or pytest which I can follow; or any tweak on this?
HowTo
You can use a session-scoped fixture in pytest. As the name implies, it gives you the possibility to run code before and after the entire test session:
- @pytest.fixture(scope='session', autouse=True)
- def session_setup_teardown():
- # setup code goes here if needed
- yield
- cleanup_testsuite()
I'm not aware of a símilar functionality in unittest - the closest is probably tearDownClass which is executed once per test class.
沒有留言:
張貼留言