We recently integrated pytest, a Pythonic test runner, with our framework. After the tests were executed, pytest threw a couple of warnings.
We decided to share our findings as the Google search results to debug the pytest-warnings were not quite revealing.
Solution: Use thepy.test -r w
command to gather additional information about the warnings.
Reporting in pytest:
The py.test
command runs the tests and displays a test summary. For a more comprehensive report use the -r
reporting command line option with pytest.
The -r option can be used to show some extra summary specified by the character following it.
-r chars show extra test summary info as specified by chars
(f)ailed, (E)error, (s)skipped, (x)failed, (X)passed
(w)pytest-warnings (p)passed, (P)passed with output,
(a)all except pP.
So if you were interested in investigating only failures, use -r f
as a command line parameter.
What triggered those pytest-warnings?
When you run the py.test
command, pytest scours through the root directory and its sub-directories looking for files:
a. Test files start with test_*.py
or end with *_test.py
b. Test classes prefixed with Test
that have no __init__
method
c. Test functions prefixed with test_
pytest ignores files that has a class with a __init__
method in them but it responsibly throws a warning about ignoring the file when it follows the pytest naming convention. In our case, we have two files in our framework that begin with Test_
but have __init__
method in them. Mystery solved!
Now that you know how to read through the pytest-warnings try out the other command line options in pytest. Use the py.test -h
command to know the list of command line options available.
If you liked this article, learn more about Qxf2’s testing services for startups.
My expertise lies in engineering high-quality software. I began my career as a manual tester at Cognizant Technology Solutions, where I worked on a healthcare project. However, due to personal reasons, I eventually left CTS and tried my hand at freelancing as a trainer. During this time, I mentored aspiring engineers on employability skills. As a hobby, I enjoyed exploring various applications and always sought out testing jobs that offered a good balance of exploratory, scripted, and automated testing.
In 2015, I joined Qxf2 and was introduced to Python, my first programming language. Over the years, I have also had the opportunity to learn other languages like JavaScript, Shell scripting (if it can be called a language at all), and more recently, Rust. Despite this exposure, Python remains my favorite language due to its simplicity and the extensive support it offers for libraries.
In my free time, I like to watch football (I support Arsenal Football Club), play football myself, and read books.
One thought on “%1$s”