Brian Okken

Developing Software with Tests

Fixing Circular Imports in Python with Protocol

The problem started when I had two classes that needed to talk to each other. Sometimes, classes need to talk to each other in both directions. The following example is made up, but mostly behaves like the original problem. Let’s say I have a Director and an Actor. The Director tells the Actor to do_action(). In order to do the action, the Actor needs to get_data() from the Director. Here’s our director....

January 23, 2023 · 4 min · Brian

Testing with Python 3.12

Python 3.12.0a2 is out. So now may be a great time to get your projects to start testing against 3.12. Note about alpha releases of Python This is from the same link as above: “During the alpha phase, features may be added up until the start of the beta phase (2023-05-08) and, if necessary, may be modified or deleted up until the release candidate phase (2023-07-31). Please keep in mind that this is a preview release and its use is not recommended for production environments....

December 5, 2022 · 3 min · Brian

Installing Python 3.11 on Mac or Windows

Installing Python from The easiest and most obvious (to me) way to install the latest version of Python on either Mac or Windows is: Go to Hover over the “Downloads” link in the navigation. This will detect if you are on Mac or Windows and present you with a button called “Python 3.11.0” (or whatever the latest version is). Click that button. This downloads an installer. Run the installer....

October 26, 2022 · 4 min

Talk - Sharing is Caring - pytest fixture edition

Sharing is Caring, pytest fixture edition I gave a talk at PyBay 2022 with the above title. It’s about sharing fixtures. The source code, and the slides, are at

September 10, 2022 · 1 min · Brian

Current Git CLI workflow

Workflow Most of my interactions with git CLI, especially for quick changes, is: $ git checkout main $ git pull $ git checkout -b okken_something < code changes > $ git commit -a -m 'quick message' $ git push Then the code review and merge happen on the server. Commands Let’s break that down. git checkout main Start at the main branch. git pull Grab any changes from remote repo....

April 13, 2022 · 2 min · Brian

Lean TDD

Preface Lean TDD is an attempt to reconcile some conflicting aspects of Test Driven Development and Lean Software Development. I’ve mentioned Lean TDD on the podcast a few times and even tried to do a quick outline at the end of episode 162. This post is a more complete outline, or at least a first draft. In audio form The initial version of this post is also available in audio form as Test & Code, episode 180....

February 20, 2022 · 17 min · Brian

Beta 9.0 of Python Testing with pytest, 2nd ed, available.

The Beta 9.0 is available for Python Testing with pytest, 2nd edition, as of Feb 9, 2022. With this 9th beta release, copy edit and indexing are complete. Next it goes to layout, then to printing. Amazon has it for pre-order, listing March 22 as availability. I think we should be able to hit that. I’m excited.

February 11, 2022 · 1 min · Brian

Python Packaging Struggle for pytest Plugins

Recently, Pradyun posted a tweet commenting not on the state of Python packaging, but more on the state of the documentation and guidance. }} -- Now, at the time, I figured that was the case for people new to packaging, not myself. I’m not really an old timer with packaging, but: I have a few published packages. I’ve used both Flit and setuptools. I’ve interviewed Brett Cannon 3 times on the packaging in episodes of Test & Code....

September 22, 2021 · 2 min

Pinning Application Dependencies with pip-tools compile

pip-tools has more functionality than this, but compile alone is quite useful. Start with a loose list of dependencies in typer rich The file can have things like >= and such if you have some restrictions on your dependencies. Now install pip-tools: pip install pip-tools Then, in create a requirements.txt file with compile: pip-compile or: python -m piptools compile The output will be shown on stdout, but also in requirements....

June 9, 2021 · 1 min

Python Testing with pytest

Simple, Rapid, Effective, and Scalable by Brian Okken Do less work when testing your Python code, but be just as expressive, just as elegant, and just as readable. The pytest testing framework helps you write tests quickly and keep them readable and maintainable—with no boilerplate code. Using a robust yet simple fixture model, it’s just as easy to write small tests with pytest as it is to scale up to complex functional testing for applications, packages, and libraries....

January 12, 2017 · 2 min · Brian