0

I am new to pytest. I have 10 test files which has multiple tests defined in each test file like below

test_repo
   - features
   -step_defs
      - stress_tests
         -file1 (10 test cases)
         -file2 (3 test cases)
      - functional_tests
        - file2 (2 test cases)
        - file3 (20 test cases)

and so on.

My problem statement is - when i initiate stress tests i want to setup and tear down like below

   - setup testdb
      - run stress tests file 1 and file2 on testdb
   - tear down delete testdb after all tests are run.

So i want to setup creation and deletion of DB only once and run all 13 test cases from stress_tests.

I tried pytest_fixtures(scope="session") they get reused or called upon each test cases.

Is there a way where i can call the creation of db and dleetion of db only once after all tests run completed?

Ashu123
  • 352
  • 2
  • 6
  • 19

1 Answers1

0

Using session in fixture scope will be automatically deleted the db after all tests have been run. Based on the documentation it was said that

session: the fixture is destroyed at the end of the test session.

So you dont need to worry about delete the database

For creation of the db itself, i think you can achieve this by define the session scoped fixture in shared conftest.py module