Table of Contents | ||
---|---|---|
|
...
1. Install Pytest and configure testing
Firstly, let's install the Pytest package. Go to the File → Settings → Project → Python Interpreter → click + button → open Available Packages and type Pytest in the search field like below:
...
Info |
---|
Once the Pytest package is installed, PyCharm detects it and makes it the default project test runner. At any time you can change a test runner in the project settings. |
2. Create new test using PyCharm
For tutorial purposes let's create another test for divide() method.
...
Code Block | ||||
---|---|---|---|---|
| ||||
def test_divide(): assert divide(10, 5) == 2 assert divide(200, 1) == 200 with pytest.raises(ZeroDivisionError): divide(1, 0) |
3. Run a test
Click the green triangle and select Run 'pytest for test_oper...' to run the test:
...