Home Python An Interview with Brian Okken, the pytest Storyteller

An Interview with Brian Okken, the pytest Storyteller

An Interview with Brian Okken, the pytest Storyteller



At present we’re delighted to be chatting with Brian Okken once more. For those who missed the final time, you’ll be able to take a look at our webinar on Productive Testing with PyCharm at your comfort. Brian wears many hats together with being a number for @PythonBytes, @PythonPeople and @PythonTest podcasts. Brian can be the creator of Python Testing with pytest and has just lately launched his new pytest course. Principally, he spends his free time telling individuals they need to write good, clear automated assessments, particularly utilizing pytest.

Inform us just a little extra about your self, Brian.

I’m a software program engineer and engineering supervisor. I work with each Python and C++, and develop embedded software program for take a look at and measurement tools, largely with RF measurements surrounding WiFi and mobile communications.

I reside in Portland, Oregon. I’m a father of daughters. I prefer to backyard, however my spouse’s the actual plant skilled. My spouse and I are additionally vintage sellers.

You’re Python’s testing storyteller. When did you first become involved within the pytest neighborhood?

My first pytest weblog article was in January of 2013. I had written a customized x-unit model function-based take a look at framework for work. Because the performance of the customized framework grew, I began researching off-the-shelf alternate options. And on the time, the weblog posts and such about unittest and pytest was all kinda outdated, and a few of them had been improper. So I began the weblog (then pythontesting.web) to do an apples-to-apples comparability of unittest, pytest, and on the time, additionally nostril and doctest.

I ended up falling in love with pytest. I additionally acquired nice suggestions from pytest core devs on the weblog posts. I initially turned a bunch of weblog posts into an book. I then determined to write down Python Testing with pytest.

Throughout each editions of the e book, pytest core devs helped out a ton as technical reviewers.

You additionally run a podcast known as Check & Code. How lengthy have you ever been doing that, and the way’s it going?

Effectively, that’s been modified to “Python Check”, however it presently nonetheless resides at testandcode.com. I began that in 2015, initially “The Python Testing Podcast”. I assume the brand new identify goes back-to-roots, a bit. The podcast is nice, and I constantly get suggestions from individuals telling me they just like the refreshing perspective I’ve on testing. 

I actually needed to achieve folks that had been each writing software program and writing assessments, as the standard of fabric round writing nice assessments as a developer just isn’t nice. There’s simply not that a lot. There’s “find out how to do toy issues with TDD”, and there’s “find out how to be a QA engineer”. However there’s not loads of materials round pragmatically utilizing automated assessments to make writing software program simpler. I used to be making an attempt to fill a little bit of that gap.

However then it grew to become simply enjoyable to speak to individuals and find out about instruments and strategies. I’ve been fascinated by the packaging story round Python, so there are fairly just a few episodes round pyproject.toml and flit and such. I ought to in all probability discuss to the Hatch individuals someday.

I began podcasting and public talking across the similar time, and people actions actually made it really feel like I used to be giving again to the neighborhood and turning into extra concerned in it.

Your video course is rolling out now. Are you able to inform us just a little bit extra about that course?

Throughout re-writing the pytest e book, I stored asking myself “Would I educate somebody this in the event that they had been sitting proper subsequent to me?” and “Would I educate this now? or wait until later?”. So I had that thought strategy of imagining I had been sitting with somebody, instructing them about testing and pytest.

The unique concept for the course is to go one step additional, to undergo all the matters in the identical order because the e book and educate as I’d if we had been sitting along with a pc. It’s rising to one thing extra although. I’m in a position to embody extras. 

Listed below are just a few examples:

  • I’ve included a video exhibiting a few bash features I’ve put in my .bashrc/.zshrc to assist simply create and activate digital environments.
  • I’ve had individuals ask me to enter extra depth on TDD and BDD, so I plan on including sections for these.
  • I exploit a `dataclass` within the software being examined within the course, and use the `discipline` attribute `examine=False`, however actually don’t speak about it a lot. A course scholar has requested for more information on this, so I’m planning on a `dataclass` video to cowl some fundamentals.
  • Most significantly, a video exhibiting how superior it’s to run pytest assessments utilizing PyCharm.

I’m additionally together with any more moderen greatest practices I’ve developed within the final couple of years. And I’ll have the ability to preserve the code repo updated with present variations of Python and pytest.

What are your high 3 options of pytest?

Ah. A comparatively straightforward one. Besides it’s exhausting to stay to a few.

  • Fixtures. Separating setup and teardown out of take a look at features makes take a look at code a lot simpler to learn and tremendously simpler to purpose about.
  • Parametrization. With just a little bit of labor, you’ll be able to flip one take a look at perform into tons of take a look at instances with parametrization. It could actually really feel like table-driven testing, however the desk is correct there subsequent to the take a look at code. It’s superior.
  • Plugins. Individuals have shared some superior extensions to make tons of stuff simpler. There are particular goal plugins like pytest-django, to assist take a look at Django functions, and normal goal ones, like pytest-cov for integrating take a look at protection, and pytest-mock, to assist make mocking simpler.

Okay. There are two extra I’ve to incorporate that don’t seem to be they need to rely in opposition to the three.

  • Plain assert statements. pytest makes use of Python’s in-built assert statements. Underneath the hood, pytest makes use of a rewriting mechanism to show assert statements into calls to helper features in order that we get tremendous nice tracebacks which are really useful. However builders utilizing pytest don’t must care in regards to the implementation. They simply use assert and it really works.
  • You’ll be able to simply use features. Most take a look at frameworks, akin to unittest, are x-unit model, and require devs to derive from a base class and put all assessments as strategies in courses. However plenty of individuals don’t write loads of courses, so it’s bizarre. Easy take a look at features are means simpler, particularly whenever you’re beginning out writing assessments. You should use courses for assessments. However you don’t must.

Command line or IDE? 

Each! I actually do use each nearly day by day. pytest has highly effective command line flags and using them is essential to getting essentially the most out of pytest. Fortunately, after I’m utilizing PyCharm, I’ve entry to command line flags simply. PyCharm’s run configuration editor is simply a few clicks away and I can add command line flags for my total session, or edit them for a person take a look at run. It additionally has a particular callout for key phrases, that are nice for zooming into simply the assessments you care about. 

May you additionally share a bit about your pytest course, akin to what it covers/what to anticipate and what college students can count on to get out of it?

The course is cut up into 3 elements:

  1. pytest Major Energy covers the superpowers of pytest you must know to write down efficient assessments in pytest. These embody fixtures, parametrization, and markers that you simply’ll use day by day. You’ll be able to take this primary half and write some nice take a look at code with nothing else.
  2. pytest Working with Tasks talks about utilizing pytest with software program tasks, and contains stuff like incorporating code protection and CI, in addition to organising pytest to check scripts and functions. This half might be nice whenever you take your learnings from half one and apply them to your personal software program tasks.
  3. pytest Booster Rockets (coming quickly). I do know you’re going to like pytest, and also you’ll wish to know extra. This third half covers plugins, not simply utilizing different individuals’s, however find out how to construct your personal plugins. I additionally cowl some superior parametrization strategies.

The course covers the whole lot that the e book does. Nevertheless it additionally goes additional. I’ve discovered so much about sustaining software program tasks for the reason that e book got here out, and there are new enjoyable toys, like Hatch for packaging, that I’ll get so as to add sections on for the course.

I’m additionally together with a neighborhood package deal, with a personal Slack channel and different methods to have the ability to ask questions in the event you get caught.

I really need you to succeed. And I do know you’ll with this course. And if one thing remains to be complicated, attain out.

Are you able to study extra? Be a part of us for our upcoming webinar with Brian himself:

Be a part of the webinar

image description



Please enter your comment!
Please enter your name here