Skip to content

Instantly share code, notes, and snippets.

@Sharadh
Created July 13, 2020 03:19
Show Gist options
  • Save Sharadh/7b20cca6da23a02588f589bcbe77f590 to your computer and use it in GitHub Desktop.
Save Sharadh/7b20cca6da23a02588f589bcbe77f590 to your computer and use it in GitHub Desktop.
Code snippet to accompany blogpost on 5 pytest best practices
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