Skip to content

Pytest style fixtures outside of Pytest

License

Notifications You must be signed in to change notification settings

virtool/pyfixtures

Repository files navigation

PyFixtures

Pytest style fixtures outside of Pytest.

import asyncio
from pathlib import Path
from pyfixtures import fixture, FixtureScope

@fixture
def tmpdir() -> path:
    path = Path("temp")
    path.mkdir()
    try:
        yield path
    finally:
        path.unlink()



def mk_temp_files(tmpdir: Path):
    tmp_file = tmpdir/"tempfile.txt"
    tmp_file.touch()


async def main():
    async with FixtureScope() as scope:
        operation = await scope.bind(mk_temp_files)
        await operation()


asyncio.run(main())