Running pytest.main(…) does not collect tests
Question:
I’ve created a sub folder with test_*.py
files and additional .py
files which hold additional methods which are being called.
In the root directory of the project I’ve created main_test.py
in which I call pytest.main(['./subdfolder'])
. pytest
is being triggered but I’m getting the blow output:
============================= test session starts =============================
platform win32 -- Python 2.7.14, pytest-3.6.1, py-1.5.3, pluggy-0.6.0
rootdir: C:PycharmProjectsTestingFramework, inifile:
plugins: tap-2.2, report-0.2.1
collected 0 items
======================== no tests ran in 0.01 seconds =========================
Process finished with exit code 0
Answers:
Edited
What I’ve discovered is that I’ve approached it all wrong the command:
pytest.main()
cannot be invoked from the terminal line (i’m using PyCharm) the correct approach is would be to place the all of the code inside of if name == “main“ block in the following manner :
if __name__ == "__main__":
junit_path = '.Reports/Junit_' + time.strftime("%d%m%Y_%H%M%S") + '.xml'
result_log_path = '.Reports/Logs/Execution_' +
time.strftime("%d%m%Y_%H%M%S") + '.log'
pytest.main(['-v', '-x','--junitxml', junit_path, '--resultlog', result_log_path])
after that using the terminal command line I was able to call the execution by calling:
python ./<<file name>>
You need to rename the file to start with test_
. In this case main_test.py
most likely needs to be test_main.py
(reversed).
I found the answer here: 'pytest' exits with no error, but with "collected 0 items"
I’ve created a sub folder with test_*.py
files and additional .py
files which hold additional methods which are being called.
In the root directory of the project I’ve created main_test.py
in which I call pytest.main(['./subdfolder'])
. pytest
is being triggered but I’m getting the blow output:
============================= test session starts =============================
platform win32 -- Python 2.7.14, pytest-3.6.1, py-1.5.3, pluggy-0.6.0
rootdir: C:PycharmProjectsTestingFramework, inifile:
plugins: tap-2.2, report-0.2.1
collected 0 items
======================== no tests ran in 0.01 seconds =========================
Process finished with exit code 0
Edited
What I’ve discovered is that I’ve approached it all wrong the command:
pytest.main()
cannot be invoked from the terminal line (i’m using PyCharm) the correct approach is would be to place the all of the code inside of if name == “main“ block in the following manner :
if __name__ == "__main__":
junit_path = '.Reports/Junit_' + time.strftime("%d%m%Y_%H%M%S") + '.xml'
result_log_path = '.Reports/Logs/Execution_' +
time.strftime("%d%m%Y_%H%M%S") + '.log'
pytest.main(['-v', '-x','--junitxml', junit_path, '--resultlog', result_log_path])
after that using the terminal command line I was able to call the execution by calling:
python ./<<file name>>
You need to rename the file to start with test_
. In this case main_test.py
most likely needs to be test_main.py
(reversed).
I found the answer here: 'pytest' exits with no error, but with "collected 0 items"