Reputation: 23567
I am running unit tests on pycharm but some how am discovering something weird. When I started testing a class, more specifically its methods, I simply wrote test cases like the following:
# hey.py
class hey:
def hello(self):
return True
def bye(self):
return 'Bye'
# test_hey.py
from unittest import TestCase
class TestHey(TestCase):
def test_hello(self):
self.fail()
def test_bye(self):
self.fail()
When I click run, it will automatically run all tests. Great. But since today, for some of my other custom classes, it seems to only run the first one. ie) just running test_hello
and totally not testing test_bye
. I would provide an example, but the behavior is not consistent as it works sometimes and it doesn't the next. I just wanted to inquire if anyone know if I am totally missing something?
EDIT: When I comment out the test cases that are actually being ran and leaving the ones that arent ran, i get the following error:
Traceback (most recent call last):
File "C:\Program Files (x86)\JetBrains\PyCharm Community Edition 3.4.1\helpers\pycharm\utrunner.py", line 148, in <module>
testLoader.makeTest(getattr(testCaseClass, a[2]), testCaseClass))
AttributeError: 'TestLoader' object has no attribute 'makeTest'
Upvotes: 1
Views: 1885
Reputation: 40693
You can run tests from any number of places in PyCharm. Depending how you run the tests will change what tests are run.
If you right click the project or a folder then all tests within the project or folder (and its sub folders) will be run. Right click a file then all tests in the file will be run. Right click in a test case then only that test case is run. Right click inside a test method and then only that test method is run.
If you use the run configurations from the start button up top then the last known test configuration will be run. So if you were only running specific tests within that file then only those tests will be run again. You may have changed the run configuration from running all tests if you chose to re-run only failed tests at any point.
To solve the issue just right click the file or test case you want to run and select "Run 'Unittests in ...'". Would provide a screenshot, but PyCharm seems to be swallowing my keypresses.
Upvotes: 2