What happens when unittest fixtures fail

In unittest fixture syntax and flow reference, I only presented fixture methods and functions that threw no exceptions. However, in real production code, it is entirely possible for something to go wrong when setting up test fixtures. This post is simply do demonstrate exactly what happens to the flow of your test code when an exception is thrown in a fixture function. And, while I’m at it, I may as well demo the normal control flow when a test fails, asserts, or throws an exception....

June 17, 2013 · 6 min · Brian

unittest fixture syntax and flow reference

This post contains examples of how unittest test fixture functions and methods are written, and in what order they run. It may seem like a long post, but it’s mostly code examples and example output. I want this to be a useful reference for both the syntax and flow of unittest fixtures. If I missed something, please comment below, and I’ll update the post. Intro: Software Test Fixtures The term test fixtures really means two things....

June 16, 2013 · 6 min · Brian

for pip proxy, use dev instead of 1.3.1

pip pip is hands down my favorite way to install stuff in Python. If you need to use it behind a firewall, download ...

June 3, 2013 · 2 min · Brian

How not to test, part 1

or Complete coverage testing or More is Better testing The setup For the sake of this post, let’s say I’ve got a Python package that needs testing. It’s written completely in Python It has a specification fully describing the API The specification is so complete that it also covers behaviors and side effects The API is the only interface this program exposes It was written by us It was written recently It only uses base Python Therefore:...

May 21, 2013 · 5 min · Brian

pytest debug print logging in real time

There are many circumstances where it’s really great to display the output of a test while a test is running, and not wait until the end. In this post, I’m going to describe my method for getting around pytest’s output capture mechanism, so that I can see my debug print/logging statements in real time. Fast and Quick? Not always Unit tests should run fast so the entire test suite can be run quickly....

April 4, 2013 · 6 min · Brian

regex search and replace example scripts

Search and replace is such a common task that it should be a tool that’s in every command line script author’s toolbox. There are probably endless solutions to the problem. I’ve put together my standard methods for tackling the problem. I’ll also show similar Perl versions, mainly for comparisons. ...

February 8, 2013 · 4 min · Brian

Python regex Search and Replace Examples

Search and replace is such a common task that it should be a tool that’s in every command line script author’s toolbox. There are probably endless solutions to the problem. I’ve put together my standard methods for tackling the problem. I’ll also show similar Perl versions, mainly for comparisons. use models using Python with a more complex regular expression using Perl ...

February 8, 2013 · 4 min

Perl regex Search and Replace Examples

Search and replace is such a common task that it should be a tool that’s in every command line script author’s toolbox. There are probably endless solutions to the problem. I’ve put together my standard methods for tackling the problem, with Perl. You can also use Python, of course, as well as other tools like sed. Use Models In most of the following discussion, I’m just replacing ‘foo’ with ‘bar’....

February 7, 2013 · 2 min

nose introduction

This post has several examples, and covers fixtures, test discovery, asserts, running options, and running unittests and doctests. Nose’s tagline is “nose extends unittest to make testing easier”. It’s is a fairly well known python unit test framework, and can run doctests, unittests, and “no boilerplate” tests. It is a good candidate for a go-to test framework. I think a smart developer should get familiar doctest, unittest, pytest, and nose. Then decide if one of those makes the most sense for them, or if they want to keep looking for features only found in other frameworks....

January 29, 2013 · 9 min · Brian

pytest introduction

I think of pytest as the run-anything, no boilerplate, no required api, use-this-unless-you-have-a-reason-not-to test framework. This is really where testing gets fun. As with previous intro’s on this site, I’ll run through an overview, then a simple example, then throw pytest at my markdown.py project. I’ll also cover fixtures, test discovery, and running unittests with pytest. No boilerplate, no required api The doctest and unittest both come with Python. They are pretty powerful on their own, and I think you should at least know about those frameworks, and learn how to run them at least on some toy examples, as it gives you a mental framework to view other test frameworks....

January 15, 2013 · 8 min