pytest-dev / pytest

The pytest framework makes it easy to write small tests, yet scales to support complex functional testing
https://pytest.org
MIT License
11.94k stars 2.66k forks source link

scoped tmp_path_factory fixtures #5219

Open salotz opened 5 years ago

salotz commented 5 years ago

I think that there should be tmp_path_factorys and other similar fixtures with different scopes. I initially started working on this as a PR for pytest-datadir but the implementation of the scoped factories should really be upstream here. The implementation is simple:

https://github.com/gabrielcnr/pytest-datadir/pull/27/files#diff-fb0ca03425023403a38456a8f44597bfR99

The question is whether this is the way to provide them, i.e. the pattern <scope>_<fixture_name> e.g. class_tmp_path_factory.

RonnyPfannschmidt commented 5 years ago

@salotz originally pytest did plan to support "multi" scoped fixture at the declaration level (without the need to to the insane manual name-mangling, however due to a structural issue we chouldn't ship it

salotz commented 5 years ago

Ya my solution ain't the most elegant but from a user's perspective it really isn't that crazy or jarring. I was actually surprised at the paucity of these fixtures. My feeling is that it fits in well with the way that you actually use pytest for most other things, that is having hardcoded behavior from special names.