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

  • CI/CD Integration

    Integrating pytest into CI/CD environments requires thoughtful consideration of dependencies and setup. suggests separating test requirements from system requirements, often using a separate requirements file or specifying extra dependencies for packaged projects 1. This approach ensures that CI systems can efficiently load necessary test dependencies without cluttering the main application requirements. Additionally, tools like Tox can be employed to test across multiple Python versions, enhancing the robustness of the testing process 2.

    I like to use them together, but there's, I mean, there's other versions you can do, but so in CI, like continuous integration, you've got the server running your tests, but you can do something similar locally with tox.

    ---

    This setup not only streamlines the testing process but also allows for debugging specific environments, making it a versatile solution for developers.

       

    Local Testing

    Tox serves as a powerful tool for managing local testing environments, complementing pytest by simulating CI pipelines on a developer's desktop. highlights its utility in testing against multiple versions of Python or even different frameworks like Django 2. This flexibility allows developers to ensure compatibility and functionality across various environments without the need for extensive manual setup. Moreover, Tox's integration with pytest facilitates targeted debugging, enabling developers to isolate and address issues within specific environments efficiently.

    It's like a CI pipeline on your desktop, so you can test a whole bunch of stuff out.

    ---

    This capability not only enhances testing efficiency but also supports a more streamlined development workflow.

Related Episodes