Generic selectors
Exact matches only
Search in title
Search in content
Post Type Selectors
Filter by Categories
About Article
Analyze Data
Archive
Best Practices
Better Outputs
Blog
Code Optimization
Code Quality
Command Line
Course
Daily tips
Dashboard
Data Analysis & Manipulation
Data Engineer
Data Visualization
DataFrame
Delta Lake
DevOps
DuckDB
Environment Management
Feature Engineer
Git
Jupyter Notebook
LLM
LLM Tools
Machine Learning
Machine Learning & AI
Machine Learning Tools
Manage Data
MLOps
Natural Language Processing
Newsletter Archive
NumPy
Pandas
Polars
PySpark
Python Helpers
Python Tips
Python Utilities
Scrape Data
SQL
Testing
Time Series
Tools
Visualization
Visualization & Reporting
Workflow & Automation
Workflow Automation

Pytest: Shows only Failed Tests

Pytest: Shows only Failed Tests

What is pytest?

pytest is a popular Python testing framework designed to make writing and running tests simple, scalable, and expressive. It allows developers to create small, readable test functions using plain Python syntax, without requiring boilerplate code or complex setup. Pytest automatically discovers tests, provides detailed failure output, and supports powerful features like fixtures (for reusable test setup), parameterization (to test multiple inputs easily), and plugins for extended functionality. It is widely used in both small projects and large production systems because it helps ensure code reliability while keeping tests clean and easy to maintain.

When testing your function using Pytest, you might want to print only failed tests instead of both failed and successful tests. If so, add --lf to pytest. “lf” stands for “list fails”.

If you are not aware of Pytest, it is the framework that makes it easy to write small tests in Python. You can find more about Pytest from my article Pytest for Data Scientists: A Comprehensive Guide to Pytest for your Data Science Projects.

Conclusion

Filtering pytest output to show only failed tests keeps your feedback loop tight, especially as your test suite grows. Instead of scrolling through hundreds of passing tests, you can focus immediately on what needs fixing.

Read Next

Want a full CI/CD testing workflow? Read our deep dive: Build Reliable Machine Learning Pipelines with Continuous Integration. Automate your tests from local to production.

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top

Work with Khuyen Tran

Work with Khuyen Tran