markus icon indicating copy to clipboard operation
markus copied to clipboard

add pytest fixture

Open willkg opened this issue 1 year ago • 2 comments

Everyone that I've talked to that uses Markus is also using pytest and has to add something like this to their conftest.py:

from markus.testing import MetricsMock

@pytest.fixture
def metricsmock():
    with MetricsMock() as mm:
        yield mm

That seems silly. We should add it to Markus proper and document usage of the fixture.

willkg avatar Jul 20 '23 17:07 willkg

@jwhitlock suggests I read https://docs.pytest.org/en/7.4.x/how-to/writing_plugins.html .

willkg avatar Jul 20 '23 17:07 willkg

I like the idea! There's a list of packages providing plugins at https://docs.pytest.org/en/7.4.x/how-to/plugins.html, you can see how they implemented their plugin to provide fixtures.

I think it is as simple as adding that code to https://github.com/willkg/markus/blob/main/src/markus/pytest_plugin.py.

jwhitlock avatar Jul 20 '23 17:07 jwhitlock