Home > other >  Testing characters not getting printed when testing a program in pycharm
Testing characters not getting printed when testing a program in pycharm

Time:11-24

I'm studying python with the "Python Crash Course" book.

Now I have reached chapter 11 "Testing your code", and I have a question. The author has left the following note in the book:

When a test case is running, Python prints one character for each unit test as it is completed. A passing test prints a dot, a test that results in an error prints an E, and a test that results in a failed assertion prints an F. This is why you’ll see a different number of dots and characters on the first line of output when you run your test cases. If a test case takes a long time to run because it contains many unit tests, you can watch these results to get a sense of how many tests are passing.

I use Pycharm, and when I test something Pycharm does not prompt the dots that the author was talking about.

I'd appreciate it if you could help me out with my problem

I'll also leave the code I'm running here, because I thought it might help

from survey import AnonymousSurvey


class TestAnonymousSurvey(unittest.TestCase):
    """Tests for the class AnonymousSurvey."""

    def setUp(self):
        """
        Create a survey and a set of responses for use in all test methods
        """
        question = "What language did you first learn?"
        self.my_survey = AnonymousSurvey(question)
        self.responses = ['Arabic', 'Farsi', "English"]

    def test_store_single_response(self):
        """Test that a single response gets stored correctly."""
        self.my_survey.store_response(self.responses[0])
        self.assertIn(self.responses[0], self.my_survey.responses)

    def test_store_three_responses(self):
        """Test that a set of three responses is stored correctly."""
        for response in self.responses:
            self.my_survey.store_response(response)
        for response in self.responses:
            self.assertIn(response, self.my_survey.responses)```

**Thanks!**

CodePudding user response:

The default test runner that unittest uses, TextTestRunner, prints its progress output to stderr by default and is thus not captured by PyCharm.

  • Related