I stumbled upon this question that has no answer. The OP asks to unpack several variables (using pytest fixtures) and make them have their local name available to the testing function. I thought I had a clean solution, involving automatic unpacking of a dictionary:
import pytest
@pytest.fixture
def my_fix():
return {"A" : 4, "B": 6 }
def test_something(my_fix):
locals().update(my_fix)
assert A == 4
assert B == 6
This is inspired by this answer in Quora. When I run this test using pytest, it fails, because there seems to be no local variables called A
or B
!
Anyone willing to shed some light on why this happens? Also, an answer to the original question would be greatly appreciated.