Published Jun 16, 2022

Episode 516: Brian Okken on Testing in Python with pytest

Brian Okken delves into the advantages of using pytest for Python testing, focusing on its simplicity, flexibility, and powerful features like parameterization and fixtures. He also explores testing strategies with TDD, and the integration of pytest in CI/CD environments, making a case for more modular and maintainable code.
Episode Highlights
Software Engineering Radio - the podcast for professional software developers logo

Popular Clips

Episode Highlights

  • TDD Approach

    Test-driven development (TDD) is a powerful approach that emphasizes writing tests alongside production code. shares his perspective on TDD, highlighting its benefits in developing both tests and code simultaneously. He notes that while some advocate for writing tests first, he often writes tests during development to explore and understand code behavior. explains:

    I use testing for just playing. So one of the things that people will often do when they're developing code, like if you're calling, like you're developing a bunch of functions within a module, say, I want to call those functions to see what they do.

    ---

    This approach allows for flexibility and creativity in coding, enabling developers to refine their code without being constrained by initial test structures 1 2.

       

    Modular Design

    Writing tests can naturally lead to more modular and maintainable code structures. and discuss how starting with small, testable pieces encourages modular design, reducing code coupling and enhancing maintainability. Okken emphasizes the importance of designing for testing, suggesting that even simple scripts should be structured to allow for easy testing. He advises:

    Breaking your code into different functions, different modules is a good thing because then I can test individual pieces.

    ---

    This modular approach not only facilitates testing but also supports refactoring, ensuring that changes do not inadvertently break existing functionality 3 4.

Related Episodes