question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

`poetry run pytest tests` cannot import current project if tests/__init__.py does not exist

See original GitHub issue

Ran into this with Poetry 0.8.6. To reproduce this, you can delete tests/__init__.py in the Poetry project itself, then run poetry run pytest tests. On commit 4829967a37fc74b3b7715986867fbd2ade29b514, I get 25 failures on ModuleNotFoundError: No module named 'poetry'. Pytest doesn’t normally require __init__.py files, so this is surprising.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:4
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

5reactions
Jaakkonencommented, Aug 20, 2021

It looks like you need to do poetry add --dev pytest for it to work with poetry run pytest tests/. Otherwise it will not be adding your project folder to the PYTHONPATH

4reactions
mtkennerlycommented, Oct 22, 2018

This works correctly in the latest version of Poetry (0.12.4). Looks like the fix came from 0.12.0 installing the current project in editable mode when you run poetry install, so now Pytest can find the current project without needing the project folder manually added to PYTHONPATH.

Read more comments on GitHub >

github_iconTop Results From Across the Web

sub module not found with poetry run pytest - Stack Overflow
So now the problem is: if I do a test for functions.py, I import like so : from project.collect_data.functions import my_function and this...
Read more >
How to invoke pytest — pytest documentation
This will execute all tests in all files whose names follow the form test_*.py or \*_test.py in the current directory and its subdirectories....
Read more >
Testing Python in Visual Studio Code
Support for running tests in parallel with pytest is available through the pytest-xdist package. To enable parallel testing: Open the integrated terminal and ......
Read more >
pytest-cov - PyPI
Pytest plugin for measuring coverage.
Read more >
Why does PyCharm not run pytest testing for my application?
I want to test the db.py module. I configure pycharm to use pytest as my test runner ( I verified this). When I...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found