skip to navigation
skip to content

Planet Python

Last update: June 29, 2025 10:42 AM UTC

June 27, 2025


Hugo van Kemenade

Run coverage on tests

I recommend running coverage on your tests.

Here’s a couple of reasons why, from the past couple of months.

Example one #

When writing tests, it’s common to copy and paste test functions, but sometimes you forget to rename the new one (see also: the Last Line Effect).

For example:

def test_get_install_to_run_with_platform(patched_installs):
 i = installs.get_install_to_run("<none>", None, "1.0-32")
 assert i["id"] == "PythonCore-1.0-32"
 assert i["executable"].match("python.exe")
 i = installs.get_install_to_run("<none>", None, "2.0-arm64")
 assert i["id"] == "PythonCore-2.0-arm64"
 assert i["executable"].match("python.exe")


def test_get_install_to_run_with_platform(patched_installs):
 i = installs.get_install_to_run("<none>", None, "1.0-32", windowed=True)
 assert i["id"] == "PythonCore-1.0-32"
 assert i["executable"].match("pythonw.exe")
 i = installs.get_install_to_run("<none>", None, "2.0-arm64", windowed=True)
 assert i["id"] == "PythonCore-2.0-arm64"
 assert i["executable"].match("pythonw.exe")

The tests pass, but the first one is never run because its name is redefined. This clearly shows up as a non-run test in the coverage report. In this case, we only need to rename one of them, and both are covered and pass.

But sometimes there’s a bug in the test which would cause it to fail, but we just don’t know because it’s not run.

Tip 1: This can also be found by Ruff’s F811 rule.
 
Tip 2: pytest’s parametrize is a great way to combine similar test functions with different input data.

Example two #

This is more subtle:

im = Image.new("RGB", (1, 1))
for colors in (("#f00",), ("#f00", "#0f0")):
 append_images = (Image.new("RGB", (1, 1), color) for color in colors)
 im_reloaded = roundtrip(im, save_all=True, append_images=append_images)

 assert_image_equal(im, im_reloaded)
 assert isinstance(im_reloaded, MpoImagePlugin.MpoImageFile)
 assert im_reloaded.mpinfo is not None
 assert im_reloaded.mpinfo[45056] == b"0100"

 for im_expected in append_images:
 im_reloaded.seek(im_reloaded.tell() + 1)
 assert_image_similar(im_reloaded, im_expected, 1)

It’s not so obvious when looking at the code, but Codecov highlights a problem:

The same code, but Codecov has flagged the last two lines were not covered

The append_images generator is being consumed inside roundtrip(), so we have nothing to iterate over in the for loop – hence no coverage. The fix is to use a list instead of a generator.


Header photo: Misplaced manhole cover (CC BY-NC-SA 2.0 Hugo van Kemenade).

June 27, 2025 05:41 PM UTC


Real Python

The Real Python Podcast – Episode #255: Structuring Python Scripts & Exciting Non-LLM Software Trends

What goes into crafting an effective Python script? How do you organize your code, manage dependencies with PEP 723, and handle command-line arguments for the best results? Christopher Trudeau is back on the show this week, bringing another batch of PyCoder's Weekly articles and projects.

June 27, 2025 12:00 PM UTC


Luke Plant

Statically checking Python dicts for completeness

A Pythonic way to ensure that your statically-defined dicts are complete, with full source code.

June 27, 2025 10:09 AM UTC


PyPodcats

Episode 9: With Tamara Atanasoska

Learn about Tamara's journey. Tamara has been contributing to open source projects since 2012. She participated in Google Summer of Code to contribute to projects like Gnome and e-cidadania.

June 27, 2025 09:00 AM UTC


Django Weblog

Watch the DjangoCon Europe 2025 talks

They’re now all available to watch on YouTube, with a dedicated playlist ⭐️ DjangoCon Europe 2025 Dublin. For more quality Django talks in 2025, check out our next upcoming events!

All the DjangoCon Europe talks

Welcome Session Keynote: Django needs you! (to do code review) End-to-end testing Django applications using Pytest with Playwright Turn back time: Converting integer fields to bigint using Django migrations at scale Data-Oriented Django Drei The fine print in Django release notes Django + HTMX: Patterns to Success How to solve a Python mystery Bulletproof Data Pipelines: Django, Celery, and the Power of Idempotency Logs, shells, caches and other strange words we use daily Day 1 Lightning Talks How to Enjoy Debugging in Production KEYNOTE: The Most Bizarre Software Bugs in History Passkeys in Django: the best of all possible worlds How we make decisions in Django 100 Million Parking Transactions Per Year with Django One more time about µDjango Steering Council introduction Supporting Adult Career Switchers: The Unbootcamp Method How to get Foreign Keys horribly wrong in Django Zango: Accelerating Business App Development with an Opinionated Django Meta Dynamic models without dynamic models Evolving Django: What We Learned by Integrating MongoDB Feature Flags: Deploy to some of the people all of the time, and all of the Day 2 Lightning Talks KEYNOTE: Django for Data Science: Deploying Machine Learning Models with Django The incredible Djangonaut Space project Anatomy of a Database Operation One Thousand and One Django Sites Django Admin at Scale: From Milliseconds to Microseconds 🚀 Just-in-Time Development with Django and HTMX: Faster, Leaner, and Smarter Europe, Django and two-factor authentication Closing session Day 3 Lightning Talks

June 27, 2025 06:51 AM UTC

June 25, 2025


TestDriven.io

Building a Multi-tenant App with Django

This tutorial looks at how to implement multi-tenancy in Django.

June 25, 2025 10:28 PM UTC


Peter Bengtsson

Native connection pooling in Django 5 with PostgreSQL

Enabling native connection pooling in Django 5 gives me a 5.4x speedup.

June 25, 2025 09:36 PM UTC


Real Python

Your Guide to the Python print() Function

Learn how Python's print() function works, avoid common pitfalls, and explore powerful alternatives and hidden features that can improve your code.

June 25, 2025 02:00 PM UTC


Mike Driscoll

An Intro to ty – The Extremely Fast Python type checker

Ty is a brand new, extremely fast Python type checker written in Rust from the fine folks at Astral, the makers of Ruff. Ty is in preview and is not ready for production use, but you can still try it out on your code base to see how it compares to Mypy or other popular […]

The post An Intro to ty – The Extremely Fast Python type checker appeared first on Mouse Vs Python.

June 25, 2025 12:45 PM UTC


Real Python

Quiz: The Python print() Function

In this quiz, you'll test your understanding of Python's built-in print() function, covering how to format output, specify custom separators, and more.

June 25, 2025 12:00 PM UTC


PyPodcats

Trailer: Episode 9 With Tamara Atanasoska

A preview of our chat with Tamara Atanasoska. Watch the full episode on June 27, 2025

June 25, 2025 09:00 AM UTC


Talk Python to Me

#511: From Notebooks to Production Data Science Systems

If you're doing data science and have mostly spent your time doing exploratory or just local development, this could be the episode for you. We are joined by Catherine Nelson to discuss techniques and tools to move your data science game from local notebooks to full-on production workflows.

June 25, 2025 08:00 AM UTC

June 24, 2025


PyCoder’s Weekly

Issue #687: Scaling With Kubernetes, Substrings, Big-O, and More (June 24, 2025)

June 24, 2025 07:30 PM UTC


Real Python

Starting With DuckDB and Python

Learn how to use DuckDB in Python to query large datasets with SQL or its Python API, handle files like Parquet or CSV, and integrate with pandas or Polars.

June 24, 2025 02:00 PM UTC

June 23, 2025


Real Python

Python enumerate(): Simplify Loops That Need Counters

Learn how to simplify your loops with Python’s enumerate(). This tutorial shows you how to pair items with their index cleanly and effectively using real-world examples.

June 23, 2025 02:00 PM UTC


Daniel Roy Greenfeld

TIL: HTML 404 errors for FastAPI

For those times when FastAPI is serving web pages and users go to the wrong place.

June 23, 2025 01:00 PM UTC


Python Bytes

#437 Python Language Summit 2025 Highlights

Topics include The Python Language Summit 2025, Fixing Python Properties, complexipy, and juvio.

June 23, 2025 08:00 AM UTC

June 21, 2025


Will McGugan

Seeking sponsorship for Rich and Textual

After a somewhat stressful three years running a startup, I am takings a year's sabbatical. I'm going to use this time to focus on my health‐something I have neglected. As good as it feels not to work full-time, I still plan on maintaining Rich, Textual and other Open Source projects, in addition to offering free tech support.

Since I don't have any income at the moment, I want to start looking for sponsorship again. I'm hoping it will rise to a level where it will cover living costs for the year, but I'll be happy if it pays for coffee.

If you have benefited from my work in the past, consider sponsoring me. Whatever you feel comfortable with.

If your organization has extracted any value from my work, then consider picking one of the higher tiers to return the favor. I may be able to assist you with your project, wether it is terminal related or not. There is a lot of knowledge in my fleshy mammalian brain. Even in the age of AI, it could still benefit you.

June 21, 2025 04:50 PM UTC


Armin Ronacher

My First Open Source AI Generated Library

June 21, 2025 12:00 AM UTC

June 20, 2025


The Python Coding Stack

I Want to Remove Duplicates from a Python List • How Do I Do It?

Lists can have duplicate values. But sometimes, you don't want repeated items. Let's explore how to deal with this.

June 20, 2025 06:36 PM UTC


Ruslan Spivak

Book Notes: Full Frontal Calculus by Seth Braver — Chapter 1 Review

Where there is life, there is change; where there is change, there is calculus.” — Seth Braver

I recently went back to studying math to rebuild my foundations for AI and machine learning. I didn’t expect to enjoy a calculus book this much. Shocking, I know. But that’s exactly …

June 20, 2025 02:07 PM UTC


Real Python

The Real Python Podcast – Episode #254: Scaling Python Web Applications With Kubernetes and Karpenter

What goes into scaling a web application today? What are resources for learning and practicing DevOps skills? This week on the show, Calvin Hendryx-Parker is back to discuss the tools and infrastructure for autoscaling web applications with Kubernetes and Karpenter.

June 20, 2025 12:00 PM UTC

June 19, 2025


EuroPython

June Newsletter: Last Chance for Tickets!

Hello, Pythonistas! 🐍

We added a lot of new subscribers since the last newsletter – if this is your first newsletter – Welcome! 🎉

TL;DR:

June 19, 2025 08:55 PM UTC


PyCharm

Training Your ML Models With Cadence

In the rapidly evolving domains of machine learning (ML) and artificial intelligence (AI), the tools and technologies used by developers can significantly influence the speed, efficiency, and effectiveness of their projects. Recognizing this, we introduced Cadence in PyCharm 2025.1, a plugin that merges the ease of local development with advanced cloud computing capabilities. Why Cadence? […]

June 19, 2025 12:17 PM UTC

June 18, 2025


Talk Python Blog

New Theme Song: Served In A Flask

Those of you who were early listeners of Talk Python To Me might remember the amazing theme song we launched with: Developers, Developers, Developers by Smixx. Thanks to Smixx for letting us use his music for our intros.

Over the years, people have asked “What happened to the rap song”? I took it down for a couple of reasons not worth digging into but have definitely missed the fun and irreverant intro to the show.

June 18, 2025 06:55 PM UTC