There should be a way to make fixtures return **copies** of their return values #10761
Answered
by
RonnyPfannschmidt
alexander-soare
asked this question in
Ideas
-
(This could also be a question, as I'm a relatively new Pytest user) The other day I discovered that a module scoped fixture's return value is mutable by tests: @pytest.fixture(scope='module')
def fixture():
print("Running fixture")
return [0]
def test_A(fixture):
print("A:", fixture) # prints[0]
fixture[0] += 1
def test_B(fixture):
print("B: ", fixture) # prints [1] I'm not sure this is always going to be desirable behavior. Shouldn't there be an option to make sure that the return value of the fixture is copied on request? Not doing so requires developers to be vigilant, which doesn't feel like a scalable solution. |
Beta Was this translation helpful? Give feedback.
Answered by
RonnyPfannschmidt
Feb 23, 2023
Replies: 1 comment 3 replies
-
It's the intended behaviour for larger scopes If you need fresh per test use function scope |
Beta Was this translation helpful? Give feedback.
3 replies
Answer selected by
alexander-soare
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
It's the intended behaviour for larger scopes
If you need fresh per test use function scope