Three pytest features you will love

One of the most popular frameworks for Python is pytest, and it comes with several cool features. I’m going to show you three of them in this blog post.

View at original site


Author: Helen Scott

In this blog post, Helen discusses three cool features of the pytest framework for Python: fixtures, markers, and parametrize. Fixtures allow you to set up and tear down resources and conditions for tests in a consistent and reusable way. By using the @pytest.fixture decorator, you can define fixtures that are used across multiple test functions. Markers in pytest are used to run or skip tests based on certain conditions. You can use built-in markers like @pytest.mark.skip or create custom markers with custom metadata. Markers can be used to skip tests based on operating system or minimum Python version.

The @parametrize decorator in pytest allows you to run the same test with different input parameters. This improves code readability and reduces code duplication. PyCharm provides full support for pytest, including a dedicated test runner, code completion, and code navigation. If you want to learn more about these features, the author recommends checking out resources like Brian Okken's pytest course and book, watching the pytest tutorial video on JetBrains Guide, and referring to the official pytest documentation.

Related Resources

pytest vs Unittest, Which is Better?
Python, being a versatile and widely used programming language, offers several testing frameworks to facilitate the testing process. Two prominent choices are pytest and unittest, both of which come with their own sets of features and advantages.
Do you do enough testing? pytest to the rescue!
Join us to learn how you can use pytest to find bugs, improve code quality, and even have some fun along the way.
An Interview with Brian Okken - the pytest storyteller
Brian wears many hats including being a host for multiple Python podcasts and the author of Python Testing with pytest and has recently launched his new pytest course. Mostly, Brian spends his free time telling people they should write good, clean automated tests, specifically using pytest.