Learn how to enhance your testing workflow by using additional Pytest flags for greater insight into your tests.
Learn how to enhance your testing workflow by using additional Pytest flags. In this guide, you’ll see how flags like verbose mode and print statement capturing can help you gain greater insight into your tests.
This section demonstrates a simple test setup for the add function. The test, located in tests/test_calculations.py, imports the add function and verifies its correctness using an assertion.
To see more detailed information during test execution, you can use the -v (verbose) flag. This flag lists each test function being run, rather than replacing the output with simple dots. To explore all available options, run:
By default, Pytest captures output from print statements. As a result, even though the test function includes a print statement, you won’t see “testing add function” in the default output. To disable this output capture and display print statements during your tests, combine the -s flag with the verbosity flag:
Copy
Ask AI
pytest -v -s
The output with print statements displayed looks like this:
Using the -s flag is particularly useful when debugging tests that rely heavily on console output.
This guide has demonstrated how Pytest flags can be leveraged to improve the clarity and amount of information displayed during tests. Whether you’re running tests in a local development environment or as part of an automated pipeline, these flags can significantly enhance your debugging and verification process.