Pytest test discovery in subfolders

1.7k Views Asked by At

Hi I have the following project architecture, I am using selenium with pytest

enter image description here

  • From the terminal, when I am at the root folder, I can not run one the tests inside the folder "\tests"
  • As far as you know Pytest should be able to discover all tests in the subfolders or I am getting this wrong?

The command I am using is: (venv) C:\Users\Mike\PycharmProjects\UI_Selenium_Framework> pytest test_logib_logout.py I am getting ERROR: file not found: test_login_logout.py

And when I run (venv) C:\Users\Mike\PycharmProjects\UI_Selenium_Framework> pytest pytest discovers all tests inside "\tests" and run it successfully

3

There are 3 best solutions below

0
FranciscoDA On

You should run pytest tests\test_login_logout.py. You have to specify the complete path from the current working directory, which is C:\Users\Mike\PycharmProjects\UI_Selenium_Framework in your case.

Note that you can also use Python's unittest module: python3 -m unittest discover tests

0
Libin Thomas On

The easiest way is to open the terminal in the folder where the pytest files are saved and run the command.
In your case the command should look like this:

(venv) C:\Users\Mike\PycharmProjects\UI_Selenium_Framework\tests> pytest test_logib_logout.py

You can also generate an html report (if you have pytest-html plugin installed) by running the command pytest test_logib_logout.py --html=testreport.html

0
Ben On

Another option is using '-k'

(venv) C:\Users\Mike\PycharmProjects\UI_Selenium_Framework> pytest -k test_login_logout.py