I want to write my test using pytest and to be able to run them (individually) in IntelliJ. I have pytest installed, along with (obviously) Python plugin for the IDE.
My test file (tests/test_main.py
) looks like that:
from app.main import sum_numbers
def test_sum_numbers():
assert sum_numbers(1, 2) == 3
assert sum_numbers(10, 20) == 30
assert sum_numbers(1, 2, -3) == 0
Running pytest
from terminal works perfectly. But IntelliJ seems to treat this as a regular file, there are no "run" icons before the declarations. Also, running the file from the IDE does nothing, as it is not treated as a test file.
What can I do?
Pytest is a Python testing framework that originated from the PyPy project. It can be used to write various types of software tests, including unit tests, integration tests, end-to-end tests, and functional tests.
PyTest is a testing framework that allows users to write test codes using Python programming language. It helps you to write simple and scalable test cases for databases, APIs, or UI. PyTest is mainly used for writing tests for APIs. It helps to write tests from simple unit tests to complex functional tests.
Here what you need to do:
1) Remove all the existing run configurations for your test file.
2) Make sure that Preferences | Tools | Python Integrated Tools | Default rest runner is set to pytest.
After that, you should see the run icon next to your test functions and right-clicking the test file should suggest running the pytest. See the docs for more details.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With