pytest versus python -m pytest
QuizMediumPython only
Tests import from pages.login_page import LoginPage. python -m pytest works from the project root, but plain pytest fails with ModuleNotFoundError: No module named 'pages'. Why?
- python -m pytest also adds the current directory to the import path (the list of folders Python searches when you import); plain pytest does not, so the project root is not importable
- plain pytest uses a different Python language version
- The pages folder must be renamed to tests
- pytest cannot import modules at all
This question is part of Pro+
Pro+ opens every question in Interview Prep and the mock interview. Every article and the first 2 questions of each topic stay free. Hands-on Selenium and API tasks follow their course lesson's own lock.