[Python] Grouping tests in pytest: Classes vs plain functions

Discussão em 'Python' iniciado por Stack, Março 4, 2025.

  1. Stack

    Stack Membro Participativo

    I'm using pytest to test my app. pytest supports 2 approaches (that I'm aware of) of how to write tests:

    1. In classes:

    test_feature.py -> class TestFeature -> def test_feature_sanity
    ​
    1. In functions:

    test_feature.py -> def test_feature_sanity
    ​

    Is the approach of grouping tests in a class needed? Is it allowed to backport unittest builtin module? Which approach would you say is better and why?

    Continue reading...

Compartilhe esta Página