pytest
testing
Links
pytest
is a robust testing framework for Python that simplifies the process of writing small, scalable tests. It offers detailed assertion introspection, auto-discovery of test modules and functions, and a rich plugin architecture, making it suitable for both simple unit tests and complex functional testing for applications and libraries.
Usage Example
Here’s a simple example of a test function using pytest
:
# content of test_sample.py
def inc(x):
return x + 1
def test_answer():
assert inc(3) == 5
To execute the test, run the following command in your terminal:
pytest
pytest
will automatically discover the test function and execute it, providing a detailed report of the test results.