@@ -33,57 +33,6 @@ def __init__(self, *args, **kwargs):
33
33
pass
34
34
self .environment = None
35
35
36
- def setUp (self ):
37
- """
38
- pytest-specific code
39
- Be careful if a subclass of BaseCase overrides setUp()
40
- You'll need to add the following line to the subclass setUp() method:
41
- super(SubClassOfBaseCase, self).setUp()
42
- """
43
- self .is_pytest = None
44
- try :
45
- # This raises an exception if the test is not coming from pytest
46
- self .is_pytest = pytest .config .option .is_pytest
47
- except Exception :
48
- # Not using pytest (probably nosetests)
49
- self .is_pytest = False
50
- if self .is_pytest :
51
- self .with_selenium = pytest .config .option .with_selenium
52
- self .with_testing_base = pytest .config .option .with_testing_base
53
- self .log_path = pytest .config .option .log_path
54
- self .browser = pytest .config .option .browser
55
- self .data = pytest .config .option .data
56
- if self .with_selenium :
57
- self .driver = browser_launcher .get_driver (self .browser )
58
-
59
- def tearDown (self ):
60
- """
61
- pytest-specific code
62
- Be careful if a subclass of BaseCase overrides setUp()
63
- You'll need to add the following line to the subclass's tearDown():
64
- super(SubClassOfBaseCase, self).tearDown()
65
- """
66
- if self .is_pytest :
67
- if self .with_selenium :
68
- # Save a screenshot if logging is on when an exception occurs
69
- if self .with_testing_base and (sys .exc_info ()[1 ] is not None ):
70
- test_id = "%s.%s.%s" % (self .__class__ .__module__ ,
71
- self .__class__ .__name__ ,
72
- self ._testMethodName )
73
- test_logpath = self .log_path + "/" + test_id
74
- if not os .path .exists (test_logpath ):
75
- os .makedirs (test_logpath )
76
- # Handle screenshot logging
77
- log_helper .log_screenshot (test_logpath , self .driver )
78
- # Handle basic test info logging
79
- log_helper .log_test_failure_data (
80
- test_logpath , self .driver , self .browser )
81
- # Handle page source logging
82
- log_helper .log_page_source (test_logpath , self .driver )
83
-
84
- # Finally close the browser
85
- self .driver .quit ()
86
-
87
36
def open (self , url ):
88
37
self .driver .get (url )
89
38
if settings .WAIT_FOR_RSC_ON_PAGE_LOADS :
@@ -236,3 +185,56 @@ def wait_for_and_dismiss_alert(self, timeout=settings.LARGE_TIMEOUT):
236
185
237
186
def wait_for_and_switch_to_alert (self , timeout = settings .LARGE_TIMEOUT ):
238
187
return page_actions .wait_for_and_switch_to_alert (self .driver , timeout )
188
+
189
+ # PyTest-Specific Code #
190
+
191
+ def setUp (self ):
192
+ """
193
+ pytest-specific code
194
+ Be careful if a subclass of BaseCase overrides setUp()
195
+ You'll need to add the following line to the subclass setUp() method:
196
+ super(SubClassOfBaseCase, self).setUp()
197
+ """
198
+ self .is_pytest = None
199
+ try :
200
+ # This raises an exception if the test is not coming from pytest
201
+ self .is_pytest = pytest .config .option .is_pytest
202
+ except Exception :
203
+ # Not using pytest (probably nosetests)
204
+ self .is_pytest = False
205
+ if self .is_pytest :
206
+ self .with_selenium = pytest .config .option .with_selenium
207
+ self .with_testing_base = pytest .config .option .with_testing_base
208
+ self .log_path = pytest .config .option .log_path
209
+ self .browser = pytest .config .option .browser
210
+ self .data = pytest .config .option .data
211
+ if self .with_selenium :
212
+ self .driver = browser_launcher .get_driver (self .browser )
213
+
214
+ def tearDown (self ):
215
+ """
216
+ pytest-specific code
217
+ Be careful if a subclass of BaseCase overrides setUp()
218
+ You'll need to add the following line to the subclass's tearDown():
219
+ super(SubClassOfBaseCase, self).tearDown()
220
+ """
221
+ if self .is_pytest :
222
+ if self .with_selenium :
223
+ # Save a screenshot if logging is on when an exception occurs
224
+ if self .with_testing_base and (sys .exc_info ()[1 ] is not None ):
225
+ test_id = "%s.%s.%s" % (self .__class__ .__module__ ,
226
+ self .__class__ .__name__ ,
227
+ self ._testMethodName )
228
+ test_logpath = self .log_path + "/" + test_id
229
+ if not os .path .exists (test_logpath ):
230
+ os .makedirs (test_logpath )
231
+ # Handle screenshot logging
232
+ log_helper .log_screenshot (test_logpath , self .driver )
233
+ # Handle basic test info logging
234
+ log_helper .log_test_failure_data (
235
+ test_logpath , self .driver , self .browser )
236
+ # Handle page source logging
237
+ log_helper .log_page_source (test_logpath , self .driver )
238
+
239
+ # Finally close the browser
240
+ self .driver .quit ()
0 commit comments