Last active
March 28, 2018 18:30
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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