Pytest stuck on collection ...
Hi I am learning to write tests for the first time and I am stuck with the PyCharm settings.
First, I had this issue in windows 11 where the pytest command would get stuck. The solution was to run a pytest comand as an administrator.
If I click on the green run symbols next to my test functions the terminal gets stuck at the collecting phase:
============================= test session starts =============================
collecting ...
I wonder if this is because the script does not find the testing functions on my project, this is the case once I run pytest from the pycharm terminal. This is my folder structure:
myproject/
docs/
examples/
src/
myproject/
functionsA.py
functionsB.py
tests/
myproject_test.py
The myproject_test.py
starts with:
from myproject.functionsA import operation1
and the error message is
ModuleNotFoundError: No module named 'myproject
'
I wonder if anyone has any advice on how to avoid these issues and how to properly run pytest from the pycharm sidebar launch icons and/or pycharm terminal.
Thanks for any advice.
请先登录再写评论。
When you run it in the terminal, do you run it from the same directory that's defined as a "Working directory" in your run configuration (Run | Edit Configurations...)?
pytest shouldn't just hang on "collecting" stage. If no tests were found, it should report so. So it seems that the process may just hang at that stage.
Hello Sergey Karpov.
I am running it on my root folder (from the file tree example above that would be:)
D:/Pycharm projects/myproject/
I came by this question which is very similar to mine and I tried adding a pyproject.toml on my root folder:
Now, the terminal gets stuck as well. This is the command I use on the root directory:
And this is the message I get:
Would you have any suggestion?
What if you run it with the following commands? Is there any additional output?
python -m pytest -s ./tests
python -m pytest -v ./tests
Do your tests' names start with the word "test"?
Thank you Sergey Karpov for the reply.
Yes all the tests start with "test".
I am having the same issues with those commands: