4
4
from server import app
5
5
6
6
7
- @pytest .fixture
7
+ @pytest .fixture ( scope = "function" )
8
8
def temp_competitions_file (tmpdir , request ):
9
9
original_competitions_file = tmpdir .join ("competitions.json" )
10
10
num_places = request .param if hasattr (request , "param" ) else "10"
@@ -25,7 +25,20 @@ def temp_competitions_file(tmpdir, request):
25
25
with open (original_competitions_file , "w" ) as competitions_file :
26
26
json .dump (initial_competitions , competitions_file , indent = 4 )
27
27
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 } " )
29
42
30
43
31
44
@pytest .fixture
@@ -34,14 +47,6 @@ def client(temp_competitions_file):
34
47
yield client
35
48
36
49
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
-
45
50
@pytest .mark .parametrize ("temp_competitions_file" , ["10" ], indirect = True )
46
51
def test_purchasePlaces_input_less_12_sucess (client , tmpdir ):
47
52
response = client .post (
0 commit comments