Skip to content

How do I get Pytest to look in my project? #9693

Answered by jwodder
transcental asked this question in Q&A
Discussion options

You must be logged in to vote

(Disregard what I wrote earlier; I misunderstood your problem.)

So your problem is that your tests try to import your project source, but it's not found. This isn't a pytest thing; it's a basic Python packaging/importing thing. In order for your package to be importable, it needs to be in sys.path. When you run just pytest, the current directory will not be in sys.path, but it will be if you instead run python -m pytest. (At least, I'm 99% sure that's how it works; I can't find where this is mentioned in the pytest documentation at the moment.) So the simple solution is to run python -m pytest instead of just pytest.

However! This is not good packaging/testing practice. What you should do…

Replies: 2 comments 6 replies

Comment options

You must be logged in to vote
3 replies
@transcental
Comment options

@nicoddemus
Comment options

@transcental
Comment options

Comment options

You must be logged in to vote
3 replies
@transcental
Comment options

@jwodder
Comment options

@transcental
Comment options

Answer selected by transcental
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants