How to use _override_settings method in unittest-xml-reporting

Best Python code snippet using unittest-xml-reporting_python

config.py

Source:config.py Github

copy

Full Screen

...133 self._original_settings = settings134 self._settings = self._replace_variables_in_settings(settings)135 self._update_full_settings()136 @implements(IConfig.set_override_settings)137 def set_override_settings(self, override_settings):138 settings = flatten_keys(override_settings, all_options=self.ALL_OPTIONS)139 self._original_override_settings = settings140 self._override_settings = self._replace_variables_in_settings(settings)141 self._update_full_settings()142 @implements(IConfig.update_override_settings)143 def update_override_settings(self, override_settings):144 settings = flatten_keys(override_settings, all_options=self.ALL_OPTIONS)145 original = self._original_override_settings.copy()146 original.update(settings)147 self._original_override_settings = original148 self._override_settings = self._replace_variables_in_settings(original)149 self._update_full_settings()150 @implements(IConfig.get_full_settings)151 def get_full_settings(self):152 return self._full_settings153 @implements(IConfig.set_workspace_dir)154 def set_workspace_dir(self, workspace: str):155 self._workspace_dir = workspace156 self._settings = self._replace_variables_in_settings(self._original_settings)157 self._override_settings = self._replace_variables_in_settings(...

Full Screen

Full Screen

django_test.py

Source:django_test.py Github

copy

Full Screen

...37 def tearDown(self):38 os.chdir(self._old_cwd)39 shutil.rmtree(self.tmpdir)40 settings._wrapped = self.old_settings41 def _override_settings(self, **kwargs):42 # see django.test.utils.override_settings43 for key, new_value in kwargs.items():44 setattr(self.override, key, new_value)45 def _check_runner(self, runner):46 suite = runner.build_suite(test_labels=['app2', 'app'])47 test_ids = [test.id() for test in suite]48 self.assertEqual(test_ids, [49 'app2.tests.DummyTestCase.test_pass',50 'app.tests.DummyTestCase.test_negative_comment1',51 'app.tests.DummyTestCase.test_negative_comment2',52 'app.tests.DummyTestCase.test_pass',53 ])54 suite = runner.build_suite(test_labels=[])55 test_ids = [test.id() for test in suite]56 self.assertEqual(set(test_ids), set([57 'app.tests.DummyTestCase.test_pass',58 'app.tests.DummyTestCase.test_negative_comment1',59 'app.tests.DummyTestCase.test_negative_comment2',60 'app2.tests.DummyTestCase.test_pass',61 ]))62 def test_django_runner(self):63 runner_class = get_runner(settings)64 runner = runner_class()65 self._check_runner(runner)66 def test_django_xmlrunner(self):67 self._override_settings(68 TEST_RUNNER='xmlrunner.extra.djangotestrunner.XMLTestRunner')69 runner_class = get_runner(settings)70 runner = runner_class()71 self._check_runner(runner)72 def test_django_verbose(self):73 self._override_settings(74 TEST_OUTPUT_VERBOSE=True,75 TEST_RUNNER='xmlrunner.extra.djangotestrunner.XMLTestRunner')76 runner_class = get_runner(settings)77 runner = runner_class()78 self._check_runner(runner)79 def test_django_single_report(self):80 self._override_settings(81 TEST_OUTPUT_DIR=self.tmpdir,82 TEST_OUTPUT_FILE_NAME='results.xml',83 TEST_OUTPUT_VERBOSE=0,84 TEST_RUNNER='xmlrunner.extra.djangotestrunner.XMLTestRunner')85 apps.populate(settings.INSTALLED_APPS)86 runner_class = get_runner(settings)87 runner = runner_class()88 suite = runner.build_suite()89 runner.run_suite(suite)90 expected_file = path.join(self.tmpdir, 'results.xml')91 self.assertTrue(path.exists(expected_file),92 'did not generate xml report where expected.')93 def test_django_single_report_create_folder(self):94 intermediate_directory = 'report'95 directory = path.join(self.tmpdir, intermediate_directory)96 self._override_settings(97 TEST_OUTPUT_DIR=directory,98 TEST_OUTPUT_FILE_NAME='results.xml',99 TEST_OUTPUT_VERBOSE=0,100 TEST_RUNNER='xmlrunner.extra.djangotestrunner.XMLTestRunner')101 apps.populate(settings.INSTALLED_APPS)102 runner_class = get_runner(settings)103 runner = runner_class()104 suite = runner.build_suite()105 runner.run_suite(suite)106 expected_file = path.join(directory, 'results.xml')107 self.assertTrue(path.exists(expected_file),108 'did not generate xml report where expected.')109 def test_django_multiple_reports(self):110 self._override_settings(111 TEST_OUTPUT_DIR=self.tmpdir,112 TEST_OUTPUT_VERBOSE=0,113 TEST_RUNNER='xmlrunner.extra.djangotestrunner.XMLTestRunner')114 apps.populate(settings.INSTALLED_APPS)115 runner_class = get_runner(settings)116 runner = runner_class()117 suite = runner.build_suite(test_labels=None)118 runner.run_suite(suite)119 test_files = glob.glob(path.join(self.tmpdir, 'TEST*.xml'))120 self.assertTrue(test_files,121 'did not generate xml reports where expected.')122 self.assertEqual(2, len(test_files))123 def test_django_runner_extension(self):124 from xmlrunner.extra.djangotestrunner import XMLTestRunner125 class MyDjangoRunner(XMLTestRunner):126 test_runner = mock.Mock()127 128 self._override_settings(129 TEST_OUTPUT_DIR=self.tmpdir,130 TEST_OUTPUT_VERBOSE=0)131 apps.populate(settings.INSTALLED_APPS)132 runner = MyDjangoRunner()133 suite = runner.build_suite(test_labels=None)134 runner.run_suite(suite)135 ...

Full Screen

Full Screen

pkgsettings.py

Source:pkgsettings.py Github

copy

Full Screen

1import functools2import warnings3class DuplicateConfigureWarning(UserWarning):4 pass5class SimpleSettings(object):6 def as_dict(self):7 return self.__dict__8class Settings(object):9 def __init__(self):10 self._chain = [SimpleSettings()]11 self._override_settings = {}12 def __getattr__(self, attr):13 for item in self._chain:14 try:15 return getattr(item, attr)16 except AttributeError:17 pass18 raise AttributeError(attr)19 def as_dict(self):20 result = dict()21 for item in reversed(self._chain):22 result.update(item.as_dict())23 return result24 def children(self):25 """26 Tries to return a generator of all settings objects in the chain, recursively.27 This might not yield all settings objects, if they include28 other settings objects not by using the children() call.29 :return: generator of settings objects.30 """31 for child in self._chain:32 yield child33 children = getattr(child, "children", None)34 if callable(children):35 for settings in children():36 yield settings37 def _has_duplicates(self):38 """39 Check if there are duplicates in the chained settings objects.40 :return: True if there are duplicate, False otherwise.41 """42 children = set()43 for settings in self.children():44 if settings in children:45 return True46 children.add(settings)47 return False48 def configure(self, obj=None, **kwargs):49 """50 Settings that will be used by the time_execution decorator51 Attributes:52 obj (Optional[object]): Class or object with the settings as attributes53 backends (list): List of backends54 hooks (list): List of hooks55 duration_field (string): Name of the field to store the duration value56 """57 if not obj:58 obj = SimpleSettings()59 for key, new_value in kwargs.items():60 setattr(obj, key, new_value)61 if obj is self:62 warnings.warn("Refusing to add ourselves to the chain", DuplicateConfigureWarning)63 return64 self._chain.insert(0, obj)65 if self._has_duplicates():66 warnings.warn("One setting was added multiple times, maybe a loop?", DuplicateConfigureWarning)67 def __enter__(self):68 self._override_enable()69 def __exit__(self, exc_type, exc_value, traceback):70 self._override_disable()71 def __call__(self, func=None, *args, **kwargs):72 if func:73 @functools.wraps(func)74 def inner(*args, **kwargs):75 with self:76 return func(*args, **kwargs)77 return inner78 elif kwargs:79 self._override_settings = kwargs80 return self81 def _override_enable(self):82 obj = SimpleSettings()83 for key, new_value in self._override_settings.items():84 setattr(obj, key, new_value)85 self._chain.insert(0, obj)86 def _override_disable(self):87 self._chain.pop(0)88 self._override_settings = {}89class PrefixedSettings(object):90 def __init__(self, settings, prefix=None):91 self.settings = settings92 self.prefix = prefix93 def __getattr__(self, attr):94 if self.prefix:95 attr = self.prefix + attr...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run unittest-xml-reporting automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful