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 requirements.in: typer rich The requirements.in 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 requirements.in or: python -m piptools compile requirements.in 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

PythonBytes.fm

Michael Kennedy from Talk Python to Me and I have launched a new podcast, called Python Bytes, “Python headlines delivered directly to your earbuds”. It’s a weekly short format podcast. Please check it out. The first few weeks of a podcast can really make a difference if we can get a bunch of listeners to try it right away. Please consider leaving a review on iTunes. Even if you don’t use iTunes to listen, early reviews can really help with visibility....

November 10, 2016 · 1 min · Brian

Transcript for episode 2: Pytest vs Unittest vs Nose

This is the transcript for Test and Code Podcast episode 2 Hello everyone. My name is Brian Okken. Welcome to the Python Test Podcast (Now called “Test & Code”). Today I want to talk about choosing a test framework. When I went to look at the different frameworks, I noticed that unittest and doctest are part of the standard library, but nose and pytest were used quite a bit also, so I figured those four were good things to look into....

September 25, 2016 · 10 min · Brian

Python featured in April issue of PragPub

PragPub April 2016 featuring Python (and me) PragPub is the digital magazine put out by Pragmatic Bookshelf, Michael Swaine, and Nancy Groth. I’m especially excited about it because I have two articles featured. I mostly know Michael from the many years of reading Dr Dobb’s. And I respect Pragmatic Bookshelf for their work in technical publishing. So I was thrilled to be asked to contribute. From the Contents page:...

April 6, 2016 · 1 min · Brian

Given-When-Then

Designing your test methods using a simple structure such as given-when-then will help you: Communicate the purpose of your test more clearly Focus your thinking while writing the test Make test writing faster Make it easier to re-use parts of your test Highlight the assumptions you are making about the test preconditions Highlight what outcomes you are expecting and testing against. In this post I’ll be talking about designing your test cases/test methods using given-when-then. It doesn’t matter if you are using pytest, unittest, nose, or something completely different, this post will help you write better tests. Note: This was originally a writeup done after the Python Test Podcast episode 10. However, I think it stands pretty good on it’s own as a post. ...

February 10, 2016 · 11 min · Brian

pytest-expect code now in a github repo

I’ve made a few changes to the pytest-expect fixture plugin. I’ve put the plugin code on github, https://github.com/okken/pytest-expect. It is re-arranged to be a plugin installable with pip. Although I don’t have it in pypi yet. I’ve modified the code to use pytest 2.7.0 @pytest.mark.hookwrapper. I incorporated Bruno’s feedback from the last post to allow both assert failures and expect failures to be reported in the same test. There’s a tests directory to test the plugin....

March 31, 2015 · 1 min · Brian

pytest expect fixture plugin, iteration 1

This is the first iteration that implements ‘expect’ as a fixture. This is really the third attempt at an ‘expect()’ implementation that allows multiple failures per test. First attempt was a general solution that works with any test framework, but with a slightly clunky API. The main problem with it was that it required the test to call a final ‘assert_expectations()’ from the test code. If you forgot to call that function, the failures weren’t reported. Second attempt was a pytest plugin implementation that eliminated the need for the ‘assert_expectations()’ call in the test because it was called automatically. I wasn’t thrilled with this solution. But it works. In the solution I’m presenting in this post, I’m moving all of the code into one file and implementing ‘expect’ as a pytest fixture. ...

March 10, 2015 · 3 min · Brian

Test First Programming / Test First Development

Occasionally referred to as Test First Development, Test First Programming is a beautiful concept that radically changed the way I approach software development. The ideas of Test First Programming and Test Driven Development are often muddled together. However, Test First is powerful enough to stand on it’s own. I think it’s important to present the concepts separately. TDD and many other agile practices build on Test First. This isn’t just about remembering the past. The lessons learned from Test First are still very important. ...

March 3, 2015 · 8 min · Brian