Question

For some odd reason I can't figure out, once I run a test on an app in PyCharm, Pycharm won't test the additional TestCases I'm adding, even after I add them.

For example, below I had a set of tests in a module which I tested, and then I added the What testcase and run the tests again--but that new test wasn't run at all!

Tests file:

from django.test import TestCase
from django.contrib.staticfiles import finders
from django.contrib.staticfiles.storage import staticfiles_storage
import os

class SimpleTest(TestCase):
    def test_basic_addition(self):
        """
        Tests that 1 + 1 always equals 2.
        """
        self.assertEqual(1 + 1, 2)

class SettingsTest(TestCase):
    def settings_loaded(self):
        self.assertIsNotNone(os.getenv('DJANGO_SETTINGS_MODULE'))

class HomePageTestCase(TestCase):
    def test_index(self):
        resp = self.client.get('/')
        self.assertEqual(resp.status_code, 200)

    def static_loaded(self):
        abs_path = finders.find('bootstrap.css')
        self.assertTrue(staticfiles_storage.exists(abs_path))

    def get_favicon(self):
        # abs_path = finders.find('favicon.ico')
        resp=self.client.get('/static/favicon.ico')
        self.assertEqual(resp.status_code, 200)

class TeamPageCase(TestCase):
    def test_loads(self):
        resp = self.client.get('/team/')
        self.assertEqual(resp.status_code, 200)

class FAQPageCase(TestCase):
    def test_loads(self):
        resp=self.client.get('/faq/')
        self.assertEqual(resp.status_code, 200)

class What(TestCase):
    def doit(self):
        self.assertEqual(3,3)

In the screenshot below, you can see that only four TestCases were run--the fifth is never touched, for some reason.

PyCharm testing suite screenshot

Why is this happening? How can I get PyCharm to run all of my test cases? Do I have to update something or run some testsync command...or something?

Was it helpful?

Solution

Your screen shot shows four tests are being run, you have a total of eight tests.

The four being run are the four tests you have named def test_....

"A testcase is created by subclassing unittest.TestCase. The three individual tests are defined with methods whose names start with the letters test. This naming convention informs the test runner about which methods represent tests."

Rename the tests that are not running with test_ in front.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top