Skip to content

Commit c1fc303

Browse files
committed
(test) purchase handle booking more 12 places
1 parent c0699a1 commit c1fc303

File tree

1 file changed

+15
-10
lines changed

1 file changed

+15
-10
lines changed

tests/test_endpoints.py

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from server import app
55

66

7-
@pytest.fixture
7+
@pytest.fixture(scope="function")
88
def temp_competitions_file(tmpdir, request):
99
original_competitions_file = tmpdir.join("competitions.json")
1010
num_places = request.param if hasattr(request, "param") else "10"
@@ -25,7 +25,20 @@ def temp_competitions_file(tmpdir, request):
2525
with open(original_competitions_file, "w") as competitions_file:
2626
json.dump(initial_competitions, competitions_file, indent=4)
2727
app.config["COMPETITIONS_FILE"] = str(original_competitions_file)
28-
return initial_competitions
28+
29+
# Ensure the competitions are reset for each test
30+
from server import competitions
31+
32+
competitions.clear()
33+
competitions.extend(initial_competitions["competitions"])
34+
35+
yield initial_competitions
36+
37+
# Cleanup code
38+
try:
39+
tmpdir.remove(ignore_errors=True)
40+
except Exception as e:
41+
print(f"Error during cleanup: {e}")
2942

3043

3144
@pytest.fixture
@@ -34,14 +47,6 @@ def client(temp_competitions_file):
3447
yield client
3548

3649

37-
@pytest.fixture(autouse=True)
38-
def reset_competitions(temp_competitions_file):
39-
from server import competitions
40-
41-
competitions.clear()
42-
competitions.extend(temp_competitions_file["competitions"])
43-
44-
4550
@pytest.mark.parametrize("temp_competitions_file", ["10"], indirect=True)
4651
def test_purchasePlaces_input_less_12_sucess(client, tmpdir):
4752
response = client.post(

0 commit comments

Comments
 (0)