Testing Python Applications with Pytest
Pytest is
a testing framework and test runner for Python. In this guide, we will
look at the most useful configuration and usage, including several
pytest plugins and external libraries.
Pytest basics
Pytest will automatically scan our codebase for test modules, files following the file name convention test_*.py or *_test.py, and scan them for functions named test_*(). If we want to run tests defined as methods inside classes, we need to prefix the class names with Test. Pytest will also automatically pick up any tests written using unittest module.
Standard test functions and test runs
By default, fixtures are function-scoped, meaning that a fixture's
lifetime is tied to the execution of the test function. However, this
behavior can be changed to one of the other supported scopes (function, class, module, package, or session).
Pytest fixtures can also be parametrized (taking arguments). See Parametrizing fixtures in the documentation.
example code :
assert r2 == d
Comments
Post a Comment