{"id":397826,"date":"2023-10-27T12:43:55","date_gmt":"2023-10-27T11:43:55","guid":{"rendered":"https:\/\/blog.jetbrains.com\/?post_type=pycharm&#038;p=397826"},"modified":"2023-10-30T10:24:38","modified_gmt":"2023-10-30T09:24:38","slug":"an-interview-with-brian-okken-the-pytest-storyteller","status":"publish","type":"pycharm","link":"https:\/\/blog.jetbrains.com\/pycharm\/2023\/10\/an-interview-with-brian-okken-the-pytest-storyteller\/","title":{"rendered":"An Interview with Brian Okken, the pytest Storyteller"},"content":{"rendered":"\n<p>Today we\u2019re delighted to be chatting with Brian Okken again. If you missed the last time, you can check out our webinar on <a href=\"https:\/\/youtu.be\/ixqeebhUa-w\" target=\"_blank\" rel=\"noopener\">Productive Testing with PyCharm<\/a> at your convenience. Brian wears many hats including being a host for <a href=\"https:\/\/twitter.com\/PythonBytes\" target=\"_blank\" rel=\"noopener\">@PythonBytes<\/a>, <a href=\"https:\/\/twitter.com\/pythonpeople\" target=\"_blank\" rel=\"noopener\">@PythonPeople<\/a> and<a href=\"https:\/\/twitter.com\/TestAndCode\" target=\"_blank\" rel=\"noopener\"> @PythonTest<\/a> podcasts. Brian is also the author of<a href=\"http:\/\/pythontest.com\/pytest-book\" target=\"_blank\" rel=\"noopener\"> Python Testing with pytest<\/a> and has recently launched his new<a href=\"https:\/\/courses.pythontest.com\/\" target=\"_blank\" rel=\"noopener\"> pytest course<\/a>. Mostly, he spends his free time telling people they should write good, clean automated tests, specifically using pytest.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Tell us a little more about yourself, Brian.<\/h2>\n\n\n\n<p>I\u2019m a software engineer and engineering manager. I work with both Python and C++, and develop embedded software for test and measurement equipment, mostly with RF measurements surrounding WiFi and cellular communications.<\/p>\n\n\n\n<p>I live in Portland, Oregon. I\u2019m a father of daughters. I like to garden, but my wife\u2019s the real plant expert. My wife and I are also antique dealers.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">You\u2019re Python\u2019s testing storyteller. When did you first get involved in the pytest community?<\/h2>\n\n\n\n<p>My first<a href=\"https:\/\/pythontest.com\/framework\/pytest\/pytest-introduction\/\" target=\"_blank\" rel=\"noopener\"> pytest blog article<\/a> was in January of 2013. I had written a custom x-unit style function-based test framework for work. As the functionality of the custom framework grew, I started researching off-the-shelf alternatives. And at the time, the blog posts and such about unittest and pytest was all kinda old, and some of them were wrong. So I started the blog (then<a href=\"http:\/\/pythontesting.net\" target=\"_blank\" rel=\"noopener\"> pythontesting.net<\/a>) to do an apples-to-apples comparison of unittest, pytest, and at the time, also nose and doctest.<\/p>\n\n\n\n<p>I ended up falling in love with pytest. I also got great feedback from pytest core devs on the blog posts. I originally turned a bunch of blog posts into an ebook. I then decided to write<a href=\"http:\/\/pythontest.com\/pytest-book\" target=\"_blank\" rel=\"noopener\"> Python Testing with pytest<\/a>.<\/p>\n\n\n\n<p>During both editions of the book, pytest core devs helped out a ton as technical reviewers.<\/p>\n\n\n\n<!--more-->\n\n\n\n<h2 class=\"wp-block-heading\">You also run a podcast called Test &amp; Code. How long have you been doing that, and how\u2019s it going?<\/h2>\n\n\n\n<p>Well, that\u2019s been changed to \u201cPython Test\u201d, but it currently still resides at <a href=\"http:\/\/testandcode.com\" target=\"_blank\" rel=\"noopener\">testandcode.com<\/a>. I started that in 2015, originally \u201cThe Python Testing Podcast\u201d. I guess the new name is going back-to-roots, a bit. The podcast is great, and I consistently get feedback from people telling me they like the refreshing perspective I have on testing.&nbsp;<\/p>\n\n\n\n<p>I really wanted to reach people that were both writing software and writing tests, as the quality of material around writing great tests as a developer is not great. There\u2019s just not that much. There\u2019s \u201chow to do toy problems with TDD\u201d, and there\u2019s \u201chow to be a QA engineer\u201d. But there\u2019s not a lot of material around pragmatically using automated tests to make writing software easier. I was trying to fill a bit of that hole.<\/p>\n\n\n\n<p>But then it became just fun to talk to people and learn about tools and techniques. I\u2019ve been fascinated by the packaging story around Python, so there are quite a few episodes around pyproject.toml and flit and such. I should probably talk to the Hatch people sometime.<\/p>\n\n\n\n<p>I started podcasting and public speaking around the same time, and those activities really made it feel like I was giving back to the community and becoming more involved in it.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Your video course is rolling out now. Can you tell us a little bit more about that course?<\/h2>\n\n\n\n<p>During re-writing the pytest book, I kept asking myself \u201cWould I teach someone this if they were sitting right next to me?\u201d and \u201cWould I teach this now? or wait till later?\u201d. So I had that thought process of imagining I were sitting with someone, teaching them about testing and pytest.<\/p>\n\n\n\n<p>The original idea for the course is to go one step further, to go through all of the topics in the same order as the book and teach as I would if we were sitting together with a computer. It\u2019s growing to something more though. I\u2019m able to include extras.&nbsp;<\/p>\n\n\n\n<p>Here are a few examples:<\/p>\n\n\n\n<ul>\n<li>I\u2019ve included a video showing a couple of bash functions I\u2019ve put in my .bashrc\/.zshrc to help easily create and activate virtual environments.<\/li>\n\n\n\n<li>I\u2019ve had people ask me to go into more depth on TDD and BDD, so I plan on adding sections for those.<\/li>\n\n\n\n<li>I use a `dataclass` in the application being tested in the course, and use the `field` attribute `compare=False`, but really don\u2019t talk about it much. A course student has asked for more info on this, so I\u2019m planning on a `dataclass` video to cover some basics.<\/li>\n\n\n\n<li>Most importantly, a video showing how awesome it is to run pytest tests using PyCharm.<\/li>\n<\/ul>\n\n\n\n<p><br>I\u2019m also including any more recent best practices I\u2019ve developed in the last couple of years. And I\u2019ll be able to keep the code repo up to date with current versions of Python and pytest.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">What are your top 3 features of pytest?<\/h2>\n\n\n\n<p>Ah. A relatively easy one. Except it\u2019s hard to stick to three.<\/p>\n\n\n\n<ul>\n<li><strong>Fixtures<\/strong>. Separating setup and teardown out of test functions makes test code so much easier to read and tremendously easier to reason about.<\/li>\n\n\n\n<li><strong>Parametrization<\/strong>. With a little bit of work, you can turn one test function into tons of test cases with parametrization. It can feel like table-driven testing, but the table is right there next to the test code. It\u2019s awesome.<\/li>\n\n\n\n<li><strong>Plugins<\/strong>. People have shared some awesome extensions to make tons of stuff easier. There are special purpose plugins like pytest-django, to help test Django applications, and general purpose ones, like pytest-cov for integrating test coverage, and pytest-mock, to help make mocking easier.<\/li>\n<\/ul>\n\n\n\n<p><\/p>\n\n\n\n<p>Ok. There are two more I have to include that don\u2019t seem like they should count against the 3.<\/p>\n\n\n\n<ul>\n<li><strong>Plain assert statements<\/strong>. pytest uses Python\u2019s built in assert statements. Under the hood, pytest uses a rewriting mechanism to turn assert statements into calls to helper functions so that we get super great tracebacks that are actually helpful. But developers using pytest don\u2019t have to care about the implementation. They just use assert and it works.<\/li>\n\n\n\n<li><strong>You can just use functions<\/strong>. Most test frameworks, such as unittest, are x-unit style, and require devs to derive from a base class and put all tests as methods in classes. But lots of people don\u2019t write a lot of classes, so it\u2019s weird. Simple test functions are way easier, especially when you\u2019re starting out writing tests. You can use classes for tests. But you don\u2019t have to.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Command line or IDE?&nbsp;<\/h2>\n\n\n\n<p>Both! I really do use both almost every day. pytest has powerful command line flags and utilizing them is key to getting the most out of pytest. Luckily, when I\u2019m using PyCharm, I have access to command line flags easily. PyCharm\u2019s run configuration editor is just a couple of clicks away and I can add command line flags for my entire session, or edit them for an individual test run. It also has a special callout for keywords, which are great for zooming into just the tests you care about.&nbsp;<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Could you also share a bit about your pytest course, such as what it covers\/what to expect and what students can expect to get out of it?<\/h2>\n\n\n\n<p>The course is split into 3 parts:<\/p>\n\n\n\n<ol>\n<li><a href=\"https:\/\/courses.pythontest.com\/p\/pytest-primary-power\" target=\"_blank\" rel=\"noopener\">pytest Primary Power<\/a> covers the superpowers of pytest you need to know to write effective tests in pytest. These include fixtures, parametrization, and markers that you\u2019ll use every day. You can take this first part and write some great test code with nothing else.<\/li>\n\n\n\n<li><a href=\"https:\/\/courses.pythontest.com\/p\/pytest-working-with-projects\" target=\"_blank\" rel=\"noopener\">pytest Working with Projects<\/a> talks about using pytest with software projects, and includes stuff like incorporating code coverage and CI, as well as setting up pytest to test scripts and applications. This part will be great when you take your learnings from part one and apply them to your own software projects.<\/li>\n\n\n\n<li>pytest Booster Rockets (coming soon). I know you\u2019re going to love pytest, and you\u2019ll want to know more. This third part covers plugins, not just using other people\u2019s, but how to build your own plugins. I also cover some advanced parametrization techniques.<\/li>\n<\/ol>\n\n\n\n<p>The course covers everything that the book does. But it also goes further. I\u2019ve learned a lot about maintaining software projects since the book came out, and there are new fun toys, like Hatch for packaging, that I\u2019ll get to add sections on for the course.<\/p>\n\n\n\n<p>I\u2019m also including a community package, with a private Slack channel and other ways to be able to ask questions if you get stuck.<\/p>\n\n\n\n<p>I really want you to succeed. And I know you will with this course. And if something is still confusing, reach out.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<p><p>Are you ready to learn more? Join us for our upcoming webinar with Brian himself:<\/p> \n<p align=\"center\"><a class=\"jb-download-button\" href=\"https:\/\/info.jetbrains.com\/pycharm-webinar-november21-2023.html\" target=\"_blank\" rel=\"noopener\">Join the webinar<\/a><\/p><\/p>\n","protected":false},"author":1150,"featured_media":398978,"comment_status":"closed","ping_status":"closed","template":"","categories":[15,5108],"tags":[8139],"cross-post-tag":[],"acf":[],"_links":{"self":[{"href":"https:\/\/blog.jetbrains.com\/fr\/wp-json\/wp\/v2\/pycharm\/397826"}],"collection":[{"href":"https:\/\/blog.jetbrains.com\/fr\/wp-json\/wp\/v2\/pycharm"}],"about":[{"href":"https:\/\/blog.jetbrains.com\/fr\/wp-json\/wp\/v2\/types\/pycharm"}],"author":[{"embeddable":true,"href":"https:\/\/blog.jetbrains.com\/fr\/wp-json\/wp\/v2\/users\/1150"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.jetbrains.com\/fr\/wp-json\/wp\/v2\/comments?post=397826"}],"version-history":[{"count":11,"href":"https:\/\/blog.jetbrains.com\/fr\/wp-json\/wp\/v2\/pycharm\/397826\/revisions"}],"predecessor-version":[{"id":404695,"href":"https:\/\/blog.jetbrains.com\/fr\/wp-json\/wp\/v2\/pycharm\/397826\/revisions\/404695"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blog.jetbrains.com\/fr\/wp-json\/wp\/v2\/media\/398978"}],"wp:attachment":[{"href":"https:\/\/blog.jetbrains.com\/fr\/wp-json\/wp\/v2\/media?parent=397826"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.jetbrains.com\/fr\/wp-json\/wp\/v2\/categories?post=397826"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.jetbrains.com\/fr\/wp-json\/wp\/v2\/tags?post=397826"},{"taxonomy":"cross-post-tag","embeddable":true,"href":"https:\/\/blog.jetbrains.com\/fr\/wp-json\/wp\/v2\/cross-post-tag?post=397826"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}