Skip to content

Instantly share code, notes, and snippets.

@radiotaiso
Last active March 28, 2018 18:30
Show Gist options
  • Save radiotaiso/dc9e2e4279dfdce9f637e0ea3abd463b to your computer and use it in GitHub Desktop.
Save radiotaiso/dc9e2e4279dfdce9f637e0ea3abd463b to your computer and use it in GitHub Desktop.
How to use a fixture to save temporary data to use in next test using pytest
import pytest
class Asd(object):
def __init__(self):
print("initin")
self.asd = None
pass
pass
class Test_SomeClass(object):
@pytest.fixture(scope="class")
def changefixtureval(self):
changingval = {}
#asd = Asd()
# return asd
yield changingval
def test_whatever(self, changefixtureval):
# pytest.pdb.set_trace()
print(changefixtureval)
assert changefixtureval == {} , "We expected a None boi"
pass
def test_changedaval(self, changefixtureval):
assert changefixtureval == {}, "We expected a None boi"
# BUt now it changes\
changefixtureval["asd"] = "boi"
assert True
pass
def test_valhaschanged(self, changefixtureval):
print("\nchangefixtureval")
print(changefixtureval)
print(changefixtureval["asd"])
assert not changefixtureval["asd"] is None, "We expected diff than None"
assert changefixtureval["asd"] == "boi", "We expected diff than None"
# That's all folks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment