Pytest tutorial Step 4: Cannot run all tests. "No tests were found"
I saw this post: https://intellij-support.jetbrains.com/hc/en-us/community/posts/115000369850-IntelliJ-IDEA-pytest-No-tests-were-found and the others that show up now that I am writing. I am following the tutorial at https://www.youtube.com/watch?v=kwj6Hk1kJYU. When I try to run all tests:
1. It says 'Test: test', not 'pytest in tests'
2. It says 'no tests were found'
3. It created and destroyed a test database. Because it is a Django project? There's no db required for these tests.
4. The tests had run individually as shown in the tutorial video.
5. PyCharm 2020.2 on Ubuntu 18.04
Please sign in to leave a comment.
I notice now that both individual tests do say 'pytest in tests' and both still run independently as expected. They also fire right away (although it seems a lot faster than the 3 seconds the auto test is set for). But the run all tests thing is unchanged from my original post. Don't see an edit / update button here...
`Hi,
Yes, Django tests behave differently than pytest/unittest.
It does create and destroy the database, unless you override that explicitly: https://stackoverflow.com/a/7004517/10895914
If something is not working as you expect, feel free to provide code sample and describe the issue in detail.
The way you said 'Django tests behave differently..' made me wonder if that also meant they are incompatible with pytest, so I did a quick Google search and found a plug-in called 'Django-Pytest'.
1. Is Django-Pytest required to make Pytest work with Django, or is it just a helper?
2. Does it work in PyCharm? Note: I did a search for 'pycharm' on their site and got no hits.
3. Are there special rules, configurations, whatever for using Django-Pytest in Pycharm?
4. I found this: https://youtrack.jetbrains.com/issue/PY-19727?_ga=2.129060108.1269879717.1598888151-886929128.1594634004 and went to change my settings for a Django project, but as soon as I did, I got a yellow triangle with a black ! in the middle, and the words "cant fnd {0} for {1}". I have no idea what that is supposed to mean, and Googling it was useless.
I have nevertheless continued to try to use this, and have even more problems:
5. Not found
(no name '/home/Projects/lifeandtimes/chronicle/tests/test_freqdist3d.py::test_freqdist' in any of [<Module test_freqdist3d.py>])
Note I ran this test by clicking the green triangle right next to test_freqdist() in test_freqdist3d.py!!!
ERROR test_freqdist3d.py
Process finished with exit code 4
Assertion failed
6. Syntax error
E File "/home/malikarumi/Projects/lifeandtimes/chronicle/tests/test_freqdist3d.py", line 8
E assert for k, v in tag_stats:
E ^
E SyntaxError: invalid syntax
How can it detect a syntax error in a function it can't find?!
7. Unresolved reference
I have 6 unresolved references in this test file, all of them to variables used in the source code function being tested. After reading some posts from other users, I decided to just run it and see what happens. So I did, and NONE of these 'unresolved references' came up in the test failure report.
8. The test folder and the source have been added as content roots and source folders.
Do you mean this by any chance https://pytest-django.readthedocs.io/en/latest/ ?
No, PyCharm don't have a specific support for them, but they should work if you run them as regular pytest configurations.