Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

pytest running tests multiple times

I have a pytest.ini file that has the following contents

[pytest]
testpaths = tests/database/* tests/*
addopts = -v --cov="merlot"  --cov="merlot/sql" --cov-report term-missing

My tests are structured such that

tests | test1.py
      | test2.py
      |
      | subfolder | test3.py
                  | test4.py
                  | test5.py

When I have testpaths = tests/* then no tests in subfolder are run, however the current invocation runs the tests in subfolder multiple times. The result looks like

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

tests/database/testDatabase.py::TestMerlotDB::testDbName PASSED                                                                                              [ 12%]
tests/database/testDatabase.py::TestMerlotDB::testResetIndex PASSED                                                                                          [ 25%]
tests/database/testDatabase.py::TestMerlotDB::testInsertRecord PASSED                                                                                        [ 37%]
tests/database/testDatabase.py::TestMerlotDB::testDbName PASSED                                                                                              [ 37%]
tests/database/testDatabase.py::TestMerlotDB::testResetIndex PASSED                                                                                          [ 37%]
tests/database/testDatabase.py::TestMerlotDB::testInsertRecord PASSED                                                                                        [ 37%]
tests/testMerlot.py::TestMerlotBrowser::testBrowser PASSED                                                                                                   [ 50%]
tests/testMerlot.py::TestMerlotBrowser::test_go_to_URL PASSED                                                                                                [ 62%]

How can I fix my pytest.ini file so that the unit tests only run one time?

>Solution :

To fix your pytest.ini so that the unit tests only run once:

[pytest]
testpaths = tests
python_files = test*.py
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading