PyCharm - no tests were found?
Solution 1
In order to recognize test functions, they must be named test_
. In your case, rename xyCheck
to test_xyCheck
:)
Solution 2
I know it's more than a year since the question was asked, but I had the same issue and that post was the first result in search.
As I understood PyCharm (or Intellij Idea Python plugin) needs your test to meet the following criteria if you want it to be launched when you run all the tests in directory.
- test functions should start with "test" (underscore is not necessary)
- the file, containing the test should also start with "test". "Test" (with capital T doesn't work in my case
I'm using Intellij IDEA 2016.3.5 with Python plugin
If you want to run you tests with command line
python -m unittest
Then you should add __init__.py
to test directory. Python still wants your test function names to start with "test", and you test file name to start with "test", but in case of files it doesn't care if the first "t" is capital or not. TestCase and test_case is equally fine.
Solution 3
One thing that can also cause this problem is if you have not selected the right testing framework in your settings:
settings > Python Integrated Tools > Testing > Default test runner
All my tests are in pytest, but it was set to unit test
Solution 4
Another gotcha that has just bitten me.
I had a test file within my test package called test_queue.py
which followed all of the above advice, however when I selected "Run UnitTests" in PyCharm the console reported no tests found.
The issue in my case was that I had a non-unit test file in the root of the project also called test_queue.py
which had been used for some other purpose early on in the project and forgotten about.
Even though I was specifically selecting the test file in my tests folder, and the path was set to absolutely point at the unit test version of the file, it seems the file in the root of the project was being used.
So, one more thing to check, make sure there are no other files in your project with the same name.
Solution 5
Don't use dashes ("-") in your filename. These files were being ignored on my machine. renaming them from project-tests.py to project_tests.py solved the problem.
ocean800
Updated on July 09, 2022Comments
-
ocean800 almost 2 years
I've been getting na error in PyCharm and I can't figure out why I'm getting it:
No tests were found
This is what I have for my
point_test.py
:import unittest import sys import os sys.path.insert(0, os.path.abspath('..')) from ..point import Point class TestPoint(unittest.TestCase): def setUp(self): pass def xyCheck(self,x,y): point = Point(x,y) self.assertEqual(x,point.x) self.assertEqual(y,point.y)
and this
point.py
, what I'm trying to test:import unittest from .utils import check_coincident, shift_point class Point(object): def __init__(self,x,y,mark={}): self.x = x self.y = y self.mark = mark def patched_coincident(self,point2): point1 = (self.x,self.y) return check_coincident(point1,point2) def patched_shift(self,x_shift,y_shift): point = (self.x,self.y) self.x,self,y = shift_point(point,x_shift,y_shift)
Is it something wrong with my run configuration? I looked at this SO post but I'm still utterly confused. My run configuration currently looks like this:
-
Charlie Parker over 2 yearsperhaps this will be useful to you: intellij-support.jetbrains.com/hc/en-us/community/posts/… to stop running in test mode.
-
-
st.huber about 6 yearsFor me the file containing the tests has to start with
test_
-
Calvin Li over 4 yearsEchoing what Ilya's answer, you also need to name the test files
test_...
otherwise you can't run the tests from their directories -
Georgios Syngouroglou over 2 yearsKeep in mind, if your tests are inside of a class, the class name should also start with the word
Text
. This question uses the class nameTestPoint
, which is correct. You could have the same error if your class name wasPointTest
.