Creating unit tests with PyCharm

We have talked about various features when it comes to examining the results from previously created unit tests in PyCharm. However, the support for testing from PyCharm does not stop there, and in this section, we will learn how to create unit tests within PyCharm.

In the same folder that we have been working with, Chapter06/Testing, open the counter.py file, which contains the following code:

import threadingimport sys; sys.setswitchinterval(.000001)class Counter:    def __init__(self, target, num_threads):        self.value = 0        self.target = target        self.num_threads = num_threads    def update(self):        current_value = self.value        self.value = current_value + 1    def run(self): threads = [threading.Thread(target=self.update) ...

Get Hands-On Application Development with PyCharm now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.