Prepare for testing
PyCharm works with multiple testing frameworks out of the box, for example, Python unittests, Pytest, Python nosetests, TwistedTrial, and Python doctests. .
In the IDE, you can create a test class directly from the source code together with the necessary test methods. You can switch between test classes and source code with a shortcut, run multiple tests, view statistics for each test, and export test results to a file.
PyCharm also features code coverage that allows you to analyze your code and understand which areas of your code are covered by tests and which areas require more testing.
PyCharm allows you to add missing libraries as you code: once the IDE detects that you're using some code from the library that is not yet added to your project, it will prompt you to download and install it.
You can also add libraries to your project manually. For example, this can be helpful if you need a specific library version or distribution.
Before you start creating tests, make sure that the Test Sources Root is configured for your project. The Test Sources Root is a folder that stores your test code. In the Project tool window, this folder is marked with the Test Root icon .
In the Project tool window (Alt01), create a new directory in which you will store your test code.
Right-click the new directory and select Mark Directory As | Test Sources Root.
The tests folder should be marked with the Test Root icon.
Thanks for your feedback!