Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pycharm - no tests were found?

I've been getting a

No tests were found

error in Pycharm and I can't figure out why I'm getting it... 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:

enter image description here

I guess I just understand what I could be doing wrong? Any help would be greatly appreciated, thanks!!

like image 620
ocean800 Avatar asked Mar 12 '16 23:03

ocean800


People also ask

Why is IntelliJ not running tests?

Check in Project settings -> Modules that you test package is marked as Tests. Right click on the test class name either in the code window or in the project panel, and select Run <classname>. If you don't see the run menu in the popup then you haven't selected a test or you don't have junit plugin installed.


2 Answers

In order to recognize test functions, they must be named test_. In your case, rename xyCheck to test_xyCheck :)

like image 172
Joran Beasley Avatar answered Oct 07 '22 14:10

Joran Beasley


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.

  1. test functions should start with "test" (underscore is not necessary)
  2. 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.

like image 39
Ilya Sazonov Avatar answered Oct 07 '22 16:10

Ilya Sazonov