Building Python Unit Tests & Exploring a Data Visualization Gallery
Digest
This episode of the Real Python podcast features Christopher Trudeau, who brings a selection of Pycoders Weekly articles and projects. The episode begins with news from the Python Software Foundation, including the opening of nominations for the PSF Board of Directors and the release of the 2023 PSF Annual Impact Report. Trudeau then dives into a Real Python article by Leadana Sposoramos on writing unit tests for Python code, covering topics like organizing tests, exploring assert methods, creating test fixtures, and debugging failing tests. He also discusses the new REPL features coming in Python 3.13, highlighting the addition of block level history and colorization. Next, Trudeau explores the Python Graph Gallery, a website featuring hundreds of charts and graphs built using popular plotting libraries, each with a foundational tutorial. The episode concludes with a discussion of software friction, inspired by an article by Hillel Wayne, and two projects: a Raspberry Pi document scanner and a library called Pacemaker for consistent loop timing.
Outlines
Introduction
This Chapter introduces the Real Python podcast and its host, Christopher Bailey. It also mentions the topics that will be covered in the episode, including interviews with experts, discussions about articles and courses, and a call to action to join the Real Python community.
Python News
This Chapter covers two pieces of news from the Python Software Foundation. The first is the opening of nominations for the PSF Board of Directors, with nominations open from June 11th to 25th and voting from July 2nd to 16th. The second is the release of the 2023 PSF Annual Impact Report, which covers highlights from the foundation in 2023 and financial reporting information for 2024.
Python's Unit Test Framework
This Chapter delves into a Real Python article by Leadana Sposoramos on writing unit tests for Python code. The article provides a comprehensive guide to using Python's built-in unit test framework, covering topics like organizing tests, exploring assert methods, creating test fixtures, and debugging failing tests. It also discusses the pros and cons of using unit tests and how to skip tests using decorators.
New REPL Features in Python 3.13
This Chapter discusses the new REPL features coming in Python 3.13, including the addition of block level history, colorization, and the ability to exit the REPL using the "exit" command. The chapter also mentions that the changes are based on the curses library, which has not yet been ported to Windows, so the new features may not be available in the Windows version of the REPL.
Python Graph Gallery
This Chapter explores the Python Graph Gallery, a website featuring hundreds of charts and graphs built using popular plotting libraries. The website provides reproducible code and explanations for each example, making it a valuable resource for anyone interested in data visualizations. The chapter highlights two particularly interesting examples: an animation using funk animation and a sandkey diagram.
Software Friction
This Chapter discusses an article by Hillel Wayne on software friction, which explores the concept of friction in the software world and how it can be addressed. The chapter draws parallels between friction in war and friction in software development, highlighting the importance of smaller scope, shorter iterations, team autonomy, redundancy, and automation. It also discusses the concept of red teaming and the importance of "eating your own dog food" to identify and address friction before releasing software to customers.
Projects
This Chapter features two projects: a Raspberry Pi document scanner and a library called Pacemaker for consistent loop timing. The Raspberry Pi document scanner project uses the Raspberry Pi, the Pi camera V2, and 3D printing to create a functional document scanner. The Pacemaker library provides a consistent time for a loop to run, which is useful for games, rate limiting API calls, real-time simulations, and animations.
Keywords
Python Software Foundation
The Python Software Foundation (PSF) is a non-profit organization that supports the Python programming language. The PSF is responsible for managing the Python language, promoting its use, and supporting the Python community. The PSF also provides funding for Python development and education.
Unit Test
Unit testing is a software testing technique that involves testing individual units of code, such as functions or methods, in isolation. Unit tests are typically written by developers and are used to ensure that each unit of code is working as expected. Unit tests are an important part of the software development process, as they help to identify and fix bugs early in the development cycle.
REPL
REPL stands for Read-Eval-Print Loop. It is an interactive programming environment that allows users to execute code line by line and see the results immediately. REPLs are often used for testing code, experimenting with new features, and learning a new programming language. Python has a built-in REPL that can be accessed by typing "python" in the terminal.
Python Graph Gallery
The Python Graph Gallery is a website that features hundreds of charts and graphs built using popular plotting libraries, such as Matplotlib, Seaborn, Plotly, and Bokeh. The website provides reproducible code and explanations for each example, making it a valuable resource for anyone interested in data visualizations. The Python Graph Gallery also includes a set of tutorials for beginners.
Software Friction
Software friction is a term used to describe the obstacles and challenges that developers face when building and maintaining software. These obstacles can include things like bugs, security vulnerabilities, integration issues, and deployment problems. Software friction can have a significant impact on the development process, leading to delays, increased costs, and reduced productivity.
Raspberry Pi
The Raspberry Pi is a series of small, low-cost single-board computers that are popular for hobbyists, educators, and makers. The Raspberry Pi is a versatile device that can be used for a wide range of projects, including robotics, home automation, and web development. The Raspberry Pi is also a popular platform for learning about computer programming and electronics.
Pacemaker
Pacemaker is a Python library that provides a consistent time for a loop to run. This is useful for applications that require real-time performance, such as games, animations, and real-time simulations. Pacemaker is aware of the wall clock and adjusts the delay between iterations to ensure that the loop runs at the desired rate.
Red Teaming
Red teaming is a security testing technique that involves simulating an attack on a system or organization. Red teamers are typically security professionals who are tasked with finding vulnerabilities and weaknesses in a system. Red teaming is an important part of the security testing process, as it helps to identify and fix vulnerabilities before they can be exploited by real attackers.
Chaos Monkey
Chaos Monkey is a tool developed by Netflix that is used to deliberately introduce failures into production systems. Chaos Monkey is designed to test the resilience of systems and ensure that they can handle unexpected failures. Chaos Monkey is a form of red teaming, as it simulates an attack on a system.
Shadow IT
Shadow IT refers to the use of technology within an organization that is not officially sanctioned or managed by the IT department. Shadow IT can arise when employees use their own devices or software to perform work tasks, or when they create their own systems without the knowledge or approval of the IT department. Shadow IT can pose a number of risks to an organization, including security risks, compliance risks, and operational risks.
Q&A
What are some of the new features coming to the Python REPL in version 3.13?
Python 3.13 will include several new features for the REPL, including block level history, colorization, and the ability to exit the REPL using the "exit" command. These features are designed to make the REPL more user-friendly and powerful.
What is the Python Graph Gallery and what makes it a valuable resource for data visualization?
The Python Graph Gallery is a website that showcases hundreds of charts and graphs built using popular Python plotting libraries. It provides reproducible code and explanations for each example, making it a great resource for learning about data visualization techniques and finding inspiration for your own projects.
What is software friction and how can it be addressed?
Software friction refers to the obstacles and challenges that developers face when building and maintaining software. These obstacles can include bugs, security vulnerabilities, integration issues, and deployment problems. To address software friction, developers can focus on smaller scope, shorter iterations, team autonomy, redundancy, and automation.
What is the purpose of the Pacemaker library?
The Pacemaker library provides a consistent time for a loop to run, which is useful for applications that require real-time performance, such as games, animations, and real-time simulations. It helps ensure that the loop runs at the desired rate, even if there are delays or stalls.
What is red teaming and how does it relate to software development?
Red teaming is a security testing technique that involves simulating an attack on a system or organization. In software development, red teaming can be used to identify and fix vulnerabilities before they can be exploited by real attackers. The concept of "eating your own dog food" is a form of red teaming, where developers use their own software to identify and address friction points.
What is shadow IT and why is it a concern for organizations?
Shadow IT refers to the use of technology within an organization that is not officially sanctioned or managed by the IT department. It can pose security risks, compliance risks, and operational risks. Organizations should be aware of shadow IT and take steps to manage it effectively.
What are some of the benefits of using Python's unit test framework?
Python's unit test framework is a powerful tool for testing code. It is built-in to the Python language, well-documented, and integrated into many IDEs. It allows developers to write tests for individual units of code, ensuring that each unit is working as expected.
What are some of the challenges of using Python's unit test framework?
One challenge of using Python's unit test framework is that it can be time-consuming to write tests for all units of code. Another challenge is that the framework can be difficult to use for testing complex code, such as code that interacts with external systems or databases.
What are some of the advantages of using the new REPL features in Python 3.13?
The new REPL features in Python 3.13, such as block level history and colorization, make the REPL more user-friendly and powerful. These features can help developers to be more productive when testing code, experimenting with new features, and learning the Python language.
What are some of the limitations of the new REPL features in Python 3.13?
One limitation of the new REPL features in Python 3.13 is that they are not yet available in the Windows version of the REPL. This is because the curses library, which the new features are based on, has not yet been ported to Windows.
Show Notes
How do you start adding unit tests to your Python code? Can the built-in unittest framework cover most or all of your needs? Christopher Trudeau is back on the show this week, bringing another batch of PyCoder’s Weekly articles and projects.
We dig into a recent tutorial by Leodanis Pozo Ramos about writing unit tests using Python’s unittest. The tutorial covers organizing your tests, exploring assert methods, creating test fixtures, and debugging failing tests.
We explore a collection of Python data visualizations and tutorials from the Python Graph Gallery. The website features hundreds of charts and graphs built using popular plotting libraries. Each chart type features a foundational tutorial that introduces the structure and application.
We also share several other articles and projects from the Python community, including a news roundup, the new REPL coming in Python 3.13, a pytest daemon to 10X test iteration speed, a discussion about software friction, a Raspberry Pi document scanner, and a project for controlling time per iteration loop.
Course Spotlight: Building a Python GUI Application With Tkinter
In this video course, you’ll learn the basics of GUI programming with Tkinter, the de facto Python GUI framework. Master GUI programming concepts such as widgets, geometry managers, and event handlers. Then, put it all together by building two applications: a temperature converter and a text editor.
Topics:
- 00:00:00 - Introduction
- 00:02:08 - Python Software Foundation Board Election Dates for 2024
- 00:02:35 - 2023 PSF Annual Impact Report
- 00:03:03 - Python’s
unittest
: Writing Unit Tests for Your Code - 00:09:41 - What’s New in Python 3.13
- 00:10:38 - The New REPL in Python 3.13
- 00:13:39 - Best Python Chart Examples
- 00:15:27 - Animation with text that highlights important events
- 00:16:39 - Sankey Diagram with Python and Plotly
- 00:18:55 - Video Course Spotlight
- 00:20:25 - Pytest Daemon: 10X Local Test Iteration Speed
- 00:23:58 - Software Friction
- 00:35:41 - A Raspberry Pi Document Scanner
- 00:39:00 - pacemaker: For Controlling Time Per Iteration Loop in Python
- 00:41:55 - Thanks and goodbye
News:
Show Links:
- Python’s
unittest
: Writing Unit Tests for Your Code – In this tutorial, you’ll learn how to use the unittest framework to create unit tests for your Python code. Along the way, you’ll also learn how to create test cases, fixtures, test suites, and more. - What’s New in Python 3.13 – Python 3.13 has gone into beta, which means the feature freeze is now in place. This is the official listing of the new features in 3.13. This release includes changes to the REPL, new typing features, experimental support for disabling the GIL, dead battery removal, and more.
- The New REPL in Python 3.13 – Python 3.13 just hit feature freeze with the first beta release, and it includes a host of improvements to the REPL. Automatic indenting, block-level editing, and more make the built-in REPL more powerful and easier to use.
- Best Python Chart Examples
- Animation with text that highlights important events - Python Graph Gallery
- Sankey Diagram with Python and Plotly - Python Graph Gallery
- Pytest Daemon: 10X Local Test Iteration Speed – Discord has a large Python monolith with lots of imports, which now takes 13 seconds to start up. On the server that’s not a problem but to run a test it is. Ruby’s solution is to have a daemon that hot loads a test on a process that already has the imports completed.
Discussion:
- Software Friction – Friction is everywhere in software development. Two setbacks are more than twice as bad as one setback. This article discusses the sources of software friction and what you can do about it.
Projects:
Additional Links:
- unittest — Unit testing framework — Python 3.12.3 documentation
- Testing with Python (part 1): the basics - Bite code!
- Sankey Diagrams – A Sankey diagram says more than 1000 pie charts
- tidytuesday: Official repo for the #tidytuesday project
- tidytuesday - dataset_announcements
- Chaos Monkey
- OpenCV: OpenCV modules
- How to Train Your Robot
Level up your Python skills with our expert-led courses: