Pytest style fixtures outside of Pytest.
importasynciofrompathlibimportPathfrompyfixturesimportfixture, FixtureScope@fixturedeftmpdir() ->path:
path=Path("temp")
path.mkdir()
try:
yieldpathfinally:
path.unlink()
defmk_temp_files(tmpdir: Path):
tmp_file=tmpdir/"tempfile.txt"tmp_file.touch()
asyncdefmain():
asyncwithFixtureScope() asscope:
operation=awaitscope.bind(mk_temp_files)
awaitoperation()
asyncio.run(main())