1

I've got some expensive setup in my test project that all tests need to do. Right now it is being done per test class, which is time consuming. I'm looking for a solution that is exactly like NUnit's OneTimeSetUp() method, which runs a method at the start of a test run. There is also a OneTimeTearDown() which would be necessary too.

I've looked into unittest's setUpModule(), but I'm not sure if it is what I'm looking for because it does not work for sub modules.

Ideally with a folder structure like:

- outer_one/
----test_base.py
----inner_one/
--------inner_test_one.py
----inner_two/
--------inner_test_two.py

Then the order of execution would be:

1. test_base().setUpRun()
2. inner_test_one().executeTests()
3. inner_test_two().executeTests()
4. test_base().tearDownRun()
st0ve
  • 519
  • 3
  • 18
  • You may be able to run your own setup and teardown from main. See: https://stackoverflow.com/questions/644821/python-how-to-run-unittest-main-for-all-source-files-in-a-subdirectory – quamrana Nov 29 '19 at 10:37
  • Thats my original thought, which will work perfectly fine for CI/CD, but I can't think of a solution for local development when I want to run a single test – st0ve Nov 29 '19 at 22:22

0 Answers0