26
26
OFFSCREEN = None
27
27
28
28
29
+ def make_window_caption (request = None , prefix = 'Testing' , sep = ' - ' ) -> str :
30
+ """Centralizes test name customization.
31
+
32
+ It helps with:
33
+
34
+ 1. Tests scoped as something other than function (can't use test_name fixture)
35
+ 2. Local (non-CI) temp modifications of inter-test behavior
36
+ """
37
+ parts = [prefix ]
38
+ if request is not None :
39
+ parts .append (request .node .name )
40
+
41
+ return sep .join (parts )
42
+
43
+
29
44
def create_window (width = 1280 , height = 720 , caption = "Testing" , ** kwargs ):
30
45
global WINDOW
31
46
if not WINDOW :
@@ -39,14 +54,16 @@ def create_window(width=1280, height=720, caption="Testing", **kwargs):
39
54
return WINDOW
40
55
41
56
42
- def prepare_window (window : arcade .Window ):
57
+ def prepare_window (window : arcade .Window , caption : str | None = None ):
43
58
# Check if someone has been naughty
44
59
if window .has_exit :
45
60
raise RuntimeError ("Please do not close the global test window :D" )
46
61
47
62
window .switch_to ()
48
63
if window .get_size () < (800 , 600 ):
49
64
window .set_size (800 , 600 )
65
+ if caption :
66
+ window .set_caption (caption )
50
67
51
68
ctx = window .ctx
52
69
# ctx._atlas = None # Clear the global atlas
@@ -75,8 +92,13 @@ def prepare_window(window: arcade.Window):
75
92
window .on_update = lambda dt : None
76
93
77
94
95
+ @pytest .fixture
96
+ def test_name (request ):
97
+ return make_window_caption (request )
98
+
99
+
78
100
@pytest .fixture (scope = "function" )
79
- def ctx ():
101
+ def ctx (test_name ):
80
102
"""
81
103
Per function context.
82
104
@@ -85,25 +107,28 @@ def ctx():
85
107
"""
86
108
window = create_window ()
87
109
arcade .set_window (window )
88
- prepare_window (window )
110
+ prepare_window (window , caption = test_name )
89
111
return window .ctx
90
112
91
113
92
114
@pytest .fixture (scope = "session" )
93
- def ctx_static ():
115
+ def ctx_static (request ):
94
116
"""
95
117
Context that is shared between tests
96
118
This is the same global context.
97
119
Module scoped fixtures can inject this context.
98
120
"""
99
121
window = create_window ()
100
122
arcade .set_window (window )
101
- prepare_window (window )
123
+ # Can't use the test_name fixture here:
124
+ # 1. This fixture is session scoped
125
+ # 2. test_name is function scoped
126
+ prepare_window (window , caption = make_window_caption (request ))
102
127
return window .ctx
103
128
104
129
105
130
@pytest .fixture (scope = "function" )
106
- def window ():
131
+ def window (test_name ):
107
132
"""
108
133
Global window that is shared between tests.
109
134
@@ -113,7 +138,7 @@ def window():
113
138
"""
114
139
window = create_window ()
115
140
arcade .set_window (window )
116
- prepare_window (window )
141
+ prepare_window (window , caption = test_name )
117
142
return window
118
143
119
144
@@ -401,7 +426,7 @@ def assert_images_almost_equal(self, image1: PIL.Image.Image, image2: PIL.Image.
401
426
402
427
403
428
@pytest .fixture (scope = "function" )
404
- def offscreen ():
429
+ def offscreen (test_name ):
405
430
"""
406
431
Offscreen rendering tools.
407
432
@@ -411,7 +436,7 @@ def offscreen():
411
436
412
437
window = create_window ()
413
438
arcade .set_window (window )
414
- prepare_window (window )
439
+ prepare_window (window , caption = test_name )
415
440
416
441
if OFFSCREEN is None :
417
442
OFFSCREEN = Offscreen ()
0 commit comments