Are you confused about pytest's fixtures?
Do you struggle to understand them?
#100daysOfCode #pytest #Python
This one is for you
Do you struggle to understand them?
#100daysOfCode #pytest #Python



They can return value or produce side effects like creating/removing a database.
They can be located inside http://conftest.py or inside the test file.


For example:
* create ES index before test function
* remove ES index after test function


It returns the factory method instead of value.
You can use the factory method inside a test to get a value based on provided parameters
For example, create users with different usernames


You can change the scope of the fixture using the *scope* parameter:
* 'module' - before/after all tests in the module
* 'session' - before first and after the last test in the test suite


* fixture's params argument
* pytest's request
An example


- tmp_path: pathlib.Path object to a temporary directory unique to each test function
- request: information on the executing test function
- caplog: Control logging and access log entries
- ...
Examples


https://docs.pytest.org/en/latest/fixture.html?highlight=fixtures