What's the best way to breakup a large test in pytest

26 Views Asked by At

I am facing some difficuilty desiding on the best way to structure a large test. This is more of an end-to-end test of a particular workflow within the application.

I am using python 3.11 and pytest.

My current test stands like this

def test_workflow(fixture_1, fixture_2, fixture_3):
    # Some arrange code

    # Some act code

    # Lot of assert statements

I dislike having so many asserts in one test but I am not sure how to structure it otherwise.

  • I cannot put the arrange and act code to fixtures and have the assert statements in separate tests as the this code is expensive to run (especially in CI). I want the arrange and act to run just once. This is a end-to-end workflow, everything being checked is part of this one workflow.
  • I also cannot do the above and declare these fixtures as scope="module". My tests/fixtures depend on other fixtures that are defined as function scope and they are external to my part of the appilcation. I can't edit them easily.

So I am stuck having my one large test.

Is there any solutions to better structure this?

Thanks!

0

There are 0 best solutions below