File tree Expand file tree Collapse file tree 1 file changed +29
-0
lines changed Expand file tree Collapse file tree 1 file changed +29
-0
lines changed Original file line number Diff line number Diff line change @@ -172,6 +172,35 @@ def __initialize_variables(self):
172
172
self._chart_series_count = {}
173
173
self._tour_steps = {}
174
174
175
+ @classmethod
176
+ def main(self, name, file, *args):
177
+ """Run pytest if file was called with "python".
178
+ Usage example:
179
+
180
+ from seleniumbase import BaseCase
181
+ BaseCase.main(__name__, __file__)
182
+
183
+ class MyTestClass(BaseCase):
184
+ def test_example(self):
185
+ pass
186
+
187
+ The run command:
188
+ python my_test.py # (Instead of "pytest my_test.py")
189
+
190
+ This is useful when sharing code with people who may not be aware
191
+ that SeleniumBase tests are run with "pytest" instead of "python".
192
+ Now, if they accidentally type "python", the tests will still run.
193
+ Eg. "python my_test.py" instead of "pytest my_test.py".
194
+ """
195
+ if name == "__main__": # Test called with "python"
196
+ from pytest import main as pytest_main
197
+ all_args = []
198
+ for arg in args:
199
+ all_args.append(arg)
200
+ for arg in sys.argv[1:]:
201
+ all_args.append(arg)
202
+ pytest_main([file, "-s", *all_args])
203
+
175
204
def open(self, url):
176
205
"""Navigates the current browser window to the specified page."""
177
206
self.__check_scope()
You can’t perform that action at this time.
0 commit comments