pytest-grpc icon indicating copy to clipboard operation
pytest-grpc copied to clipboard

Example needed of fixture cleanup

Open jinnatar opened this issue 6 years ago • 2 comments

With the way the example fixtures are built it's not obvious how to change to a yield & do cleanup -style fixture. When testing against a real service even in a testing environment it becomes necessary to run cleanup code for guaranteeing clean results every time.

jinnatar avatar Sep 03 '19 19:09 jinnatar

Yeah. I think there is also a problem with the module scoped grpc_server fixture. This makes it impossible to clean up calls made to the servicer between individual test functions.

awichmann-mintel avatar Feb 15 '21 17:02 awichmann-mintel

Old issue, but it looks like a couple of people ran into this, and it's more of a pytest question.

I would create an additional fixture and enable auto-use. This lets the fixture be attached to every test without adding an import.

Example:

@pytest.fixture(scope="function", autouse=True)
def cleanup_grpc() -> None:
  <cleanup code here (or yield then clean after)> 

Recreating the server for every test seems inefficient, so I think session or module is the appropriate scope. (This is similar to how setUp/tearDown work in UnitTest)

curtiscook avatar Apr 06 '23 19:04 curtiscook