Running individual test files doesn't work without conftest.py
See original GitHub issueWhen I try and run an individual test without a conftest.py
file in the root directory of my project, it appears that it’s not loading modules correctly. Here’s a screenshot of what I’m doing.
The imports at the top of that test are:
import pytest
import datetime
import uuid
import kids.database as database
I would expect that pytest would have the same functionality without a conftest.py
file as it would with an empty conftest.py
file, but that appears not to be the case.
Issue Analytics
- State:
- Created 4 years ago
- Comments:6 (5 by maintainers)
Top Results From Across the Web
Why doesn't pytest load conftest.py when running only a ...
I want to separate my test runs into unit tests and API tests, I don't want to run them all in one go....
Read more >[SOLVED] PyCharm can no longer find conftest.py file for ...
I've been using PyCharm CE 2019.2.3 to run and debug tests for a library I'm developing. It's been working fine for a while,...
Read more >Parametrizing tests — pytest documentation
pytest will build a string that is the test ID for each set of values in a parametrized test. These IDs can be...
Read more >PyTest Tutorial: What is, How to Install, Framework, Assertions
To run tests only from a specific file, we can use py.test <filename> ... py.test -k methods -v – will not run any...
Read more >Pytest best practices for libraries - Towards Data Science
py files in the conftest.py, leaving the fixtures which are specific to a test module in there. One potential drawback of this approach...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Note that the ModuleNotFoundError is probably the correct behavior here: The current directory isn’t necessarily in
sys.path
(where Python looks for modules) - it only happens to work because pytest adds it to load theconftest.py
file.IMHO, the proper solution is using a virtualenv where you have a development install of your project, and/or tox.
edit: @pfctdayelise was faster!
It should, which is why #2269 is open 😉