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
12.14k stars 2.69k forks source link

built-in fixtures and multiple scopes #6888

Open sashkab opened 4 years ago

sashkab commented 4 years ago

Currently if I need to create a fixture which has scope other than function, I have to re-implement every built-in fixture locally. If pytest does not support calling fixtures with multiple scopes, it should at least provide built-in fixtures with multiple scope. For example:

Same goes for tmpdir, tmp_path, etc.

RonnyPfannschmidt commented 4 years ago

there was a initial plan to provide those via multi scoped fixtures back for pytest 3.0 which failed

@nicoddemus would it be sensible to provide this workaround/pattern until pytest is actually structured to deliver multi scope fixtures

Zac-HD commented 4 years ago

If jumping directly to multi-scoped fixtures is not feasible*, this sounds like a good workaround to me. I know Hypothesis would use monkeypatch_session!

*though variable fixture scope sounds rather prone to user error, and I'm unsure that it's a good idea at all...

casperdcl commented 3 years ago

duplicate of longstanding #363