An open API service indexing awesome lists of open source software.

https://github.com/virtool/pyfixtures

Pytest style fixtures outside of Pytest
https://github.com/virtool/pyfixtures

python

Last synced: 4 months ago
JSON representation

Pytest style fixtures outside of Pytest

Awesome Lists containing this project

README

          

# PyFixtures

[Pytest](https://docs.pytest.org/en/7.1.x/) style [fixtures](https://docs.pytest.org/en/6.2.x/fixture.html) outside of Pytest.

```python
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())

```