2

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:\PycharmProjects\TestingFramework, 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

hoefling
  • 59,418
  • 12
  • 147
  • 194
Bored002
  • 353
  • 6
  • 18
  • Is `subdfolder` the correct dir name? – hoefling Jun 24 '18 at 14:06
  • yes , one level above it sits the main_test.py where i try to call pytest.main() – Bored002 Jun 25 '18 at 13:15
  • Hmm, then you have to provide [a Minimal, Complete, and Verifiable example](https://stackoverflow.com/help/mcve) because I can't reproduce the issue - maybe your test functions have an incorrect name, thus not being collected? Make sure the test function names start with `test_`. If you have test classes, make sure their names start with `Test`. – hoefling Jun 25 '18 at 13:21
  • never mind , found the issue , basically i was trying to invoke main_test.py using the pytest invocation , when in fact i should have been calling the pytest.main() from the main_test.py which in turn should have been triggerted as regular python scriupt , silly me – Bored002 Jun 26 '18 at 11:55
  • 1
    Nice! Consider writing an answer explaining the issue so it might help others looking for a solution. – hoefling Jun 26 '18 at 12:39

2 Answers2

1

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>>   
Bored002
  • 353
  • 6
  • 18
0

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"

thenarfer
  • 405
  • 2
  • 14