How to use test_negative_comment1 method in unittest-xml-reporting

Best Python code snippet using unittest-xml-reporting_python

django_test.py

Source:django_test.py Github

copy

Full Screen

1from xmlrunner.unittest import unittest2import sys3import os4from os import path5import glob6from unittest import mock7import tempfile8import shutil9try:10 import django11except ImportError:12 django = None13else:14 from django.test.utils import get_runner15 from django.conf import settings, UserSettingsHolder16 from django.apps import apps17 settings.configure(DEBUG=True)18TESTS_DIR = path.dirname(__file__)19@unittest.skipIf(django is None, 'django not found')20class DjangoTest(unittest.TestCase):21 def setUp(self):22 self._old_cwd = os.getcwd()23 self.project_dir = path.abspath(path.join(TESTS_DIR, 'django_example'))24 self.tmpdir = tempfile.mkdtemp()25 os.chdir(self.project_dir)26 sys.path.append(self.project_dir)27 # allow changing settings28 self.old_settings = settings._wrapped29 os.environ['DJANGO_SETTINGS_MODULE'] = 'example.settings'30 settings.INSTALLED_APPS # load settings on first access31 settings.DATABASES['default'] = {}32 settings.DATABASES['default']['NAME'] = path.join(33 self.tmpdir, 'db.sqlilte3')34 # this goes around the "settings already loaded" issue.35 self.override = UserSettingsHolder(settings._wrapped)36 settings._wrapped = self.override37 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

tests.py

Source:tests.py Github

copy

Full Screen

...3class DummyTestCase(TestCase):4 def test_pass(self):5 """Test Pass"""6 pass7 def test_negative_comment1(self):8 """Use a close comment XML tag -->"""9 pass10 def test_negative_comment2(self):11 """Check XML tag </testsuites>"""...

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