Created
July 13, 2020 03:19
-
-
Save Sharadh/7b20cca6da23a02588f589bcbe77f590 to your computer and use it in GitHub Desktop.
Code snippet to accompany blogpost on 5 pytest best practices
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
from copy import deepcopy | |
import pytest | |
@pytest.fixture | |
def alex(): | |
return { | |
"name": "Alex", | |
"team": "Green", | |
} | |
@pytest.fixture | |
def bala(alex): | |
alex["name"] = "Bala" | |
return alex | |
@pytest.fixture | |
def carlos(alex): | |
_carlos = deepcopy(alex) | |
_carlos["name"] = "Carlos" | |
return _carlos | |
def test_antipattern(alex, bala): | |
assert alex == {"name": "Alex", "team": "Green"} | |
assert bala == {"name": "Bala", "team": "Green"} | |
def test_pattern(alex, carlos): | |
assert alex == {"name": "Alex", "team": "Green"} | |
assert carlos == {"name": "Carlos", "team": "Green"} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment