4👍
✅
You appear to be defining test_graph
twice, which means that the second definition will overwrite the first. And you added @pytest.fixture
to a test_
method when you used it, but @pytest.fixture
should be added to non test methods so that tests can use that fixture. Here’s how the code should probably look:
import pytest
import os
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'giddeon1.settings')
import django
django.setup()
from graphs.models import Graph, Node, Tag
@pytest.fixture
def graph():
graph = Graph.objects.get(pk='74921f18-ed5f-4759-9f0c-699a51af4307')
return graph
def test_graph():
new_graph = Graph()
assert new_graph
def test_graph_add_node(graph):
assert graph.name == 'Test1'
Above, the first method has been renamed to graph
so that the next method doesn’t override it (and now @pytest.fixture
is applied to a non-test method). Then, the 3rd method uses the graph
fixture. Make any other changes as needed.
Source:stackexchange.com