pytest session scoped fixtures

In pytest fixtures nuts and bolts, I noted that you can specify session scope so that a fixture will only run once per test session and be available across multiple test functions, classes, and modules. In this post, I’m going to show a simple example so you can see it in action. ...

March 25, 2014 · 5 min · Brian

pytest fixtures nuts and bolts

I’d like to wrap up this recent series of pytest fixture posts by presenting my version of some sort of reference. Since this post is running a bit long, here are some links to the content buried in here. Bare bones example Three ways to use a fixture Name it, usefixtures, and autouse. Usefixtures example Fixture features Return value Finalizer is teardown Request object Scope Params Toy example Real example Autouse Multiple fixtures Modularity: fixtures using other fixtures Experimental and still to cover yield_fixture ids ...

February 5, 2014 · 14 min · Brian

pytest fixtures easy example

In pytest xUnit style fixtures, I presented a problem where: Two tests exist in a test file. One uses a resource. The other doesn’t. Module level fixtures don’t work if you just want to run the one function that doesn’t use the resource. I then presented class level fixtures as a way to solve the separation problem. In this post, I’ll use pytest fixtures to solve the same problem. I’m not going into details of all the goodies you get with pytest fixtures. I’ll just stick to solving this problem. ...

January 7, 2014 · 5 min · Brian

pytest xUnit style fixtures

I’m going to cover the syntax for pytest support for xUnit style fixtures. Then I’ll give a more reasonable and typical example, using just one set of fixture functions. And then address the issue of having tests mixed in a file. Some that need the resource, and some that don’t. ...

December 28, 2013 · 5 min · Brian

pytest fixtures – part 1

Dealing with fixtures is one of the areas where pytest really shines. This is rather an incredible understatement. The xunit style of test fixtures that is used in both unittest and nose is of course supported with with pytest. And pytest rocks at this. But there is another way to deal with fixtures. It’s to think of fixtures as a set of resources that need to be set up before a test starts, and cleaned up after. Test functions, methods, classes, name wich fixtures they need. This way, fixtures aren’t set up for tests that don’t need them. This focus on the fixture as a modular resource, possibly set up once for many tests, or perhaps for each test, is a really cool way to treat fixtures. However, it took me a while to really get my head around it. I’ve been thinking about it for months, and have started many, many attempts at a ‘pytest fixture’ post. ...

November 18, 2013 · 2 min · Brian

pytest full support of unittest fixtures in pytest 2.4

I finally got around to trying pytest 2.4. Actually, I tried 2.4.2, to be specific. The first thing I wanted to try was the support for unittest fixtures. As mentioned in pytest support for unittest style fixtures, they didn’t quite work in pytest 2.3. Well, now fixtures work just like unittest, when run in pytest. I started to add strikethrough marks in the pytest support for … post, but got bored....

October 29, 2013 · 1 min · Brian

Sublime Text block/column copy/paste

One of the things I love about Vim is the visual block mode, especially column copy/paste. I’ve been using Sublime for a while, and I always forget the easiest way to do this. So now that I’ve got it figured out once more, I’m writing this so I don’t forget. The general idea is this: Copy a column of text. And remember how many lines are selected. Create multiple cursors where you want to paste....

October 23, 2013 · 2 min · Brian

The power of “Thank You”

Many projects have release notes that include the names of people that contributed to the release. Who reads these names? Well, at the very least, the people in that list read the names. Fozzie: Nobody reads those names anyway, do they? Kermit: Sure. They all have families. – The Great Muppet Caper If your project doesn’t do this, I think it should. My name was listed in a release notice today. I’ll share the details, and try to point out why saying thanks to contributors is a good idea. ...

October 1, 2013 · 3 min · Brian

nose fixture reference

I’m going to cover nose setup and teardown fixtures at the package, module, class, method, and function level. This isn’t about what code to put into the fixtures, just about the syntax and flow. And a bit about naming conventions. ...

August 30, 2013 · 4 min · Brian

tip: dictionary get() works like getattr

You can’t use getattr() to look stuff up in a dictionary. But the ‘default’ feature of getattr() is so useful. What’s the dict way to do the same thing? This is one of those posts that I’m writing because I keep having to look it up. So if I write it, I’ll remember it. Hopefully. getattr I’ve been using the ‘default’ parameter to getattr for some time, and it’s super handy....

August 21, 2013 · 1 min · Brian