Best Python code snippet using tappy_python
test_tracker.py
Source:test_tracker.py
...38 tempdir = tempfile.mkdtemp()39 outdir = os.path.join(tempdir, "non", "existent", "path")40 tracker = Tracker(outdir=outdir)41 tracker.add_ok("FakeTestCase", "I should be in the specified dir.")42 tracker.generate_tap_reports()43 tap_file = os.path.join(outdir, "FakeTestCase.tap")44 self.assertTrue(os.path.exists(tap_file))45 def test_generates_tap_reports_in_existing_outdir(self):46 outdir = tempfile.mkdtemp()47 tracker = Tracker(outdir=outdir)48 tracker.add_ok("FakeTestCase", "I should be in the specified dir.")49 tracker.generate_tap_reports()50 tap_file = os.path.join(outdir, "FakeTestCase.tap")51 self.assertTrue(os.path.exists(tap_file))52 def test_results_not_combined_by_default(self):53 tracker = Tracker()54 self.assertFalse(tracker.combined)55 def test_individual_report_has_no_plan_when_combined(self):56 outdir = tempfile.mkdtemp()57 tracker = Tracker(outdir=outdir, combined=True)58 tracker.add_ok("FakeTestCase", "Look ma, no plan!")59 out_file = StringIO()60 tracker.generate_tap_report(61 "FakeTestCase", tracker._test_cases["FakeTestCase"], out_file62 )63 report = out_file.getvalue()64 self.assertTrue("Look ma" in report)65 self.assertFalse("1.." in report)66 @mock.patch("tap.tracker.ENABLE_VERSION_13", False)67 def test_combined_results_in_one_file_tap_version_12(self):68 outdir = tempfile.mkdtemp()69 tracker = Tracker(outdir=outdir, combined=True)70 tracker.add_ok("FakeTestCase", "YESSS!")71 tracker.add_ok("DifferentFakeTestCase", "GOAAL!")72 tracker.generate_tap_reports()73 self.assertFalse(os.path.exists(os.path.join(outdir, "FakeTestCase.tap")))74 self.assertFalse(75 os.path.exists(os.path.join(outdir, "DifferentFakeTestCase.tap"))76 )77 with open(os.path.join(outdir, "testresults.tap"), "r") as f:78 report = f.read()79 expected = inspect.cleandoc(80 """{header_1}81 ok 1 YESSS!82 {header_2}83 ok 2 GOAAL!84 1..285 """.format(86 header_1=self._make_header("FakeTestCase"),87 header_2=self._make_header("DifferentFakeTestCase"),88 )89 )90 self.assertEqual(report.strip(), expected)91 @mock.patch("tap.tracker.ENABLE_VERSION_13", True)92 def test_combined_results_in_one_file_tap_version_13(self):93 outdir = tempfile.mkdtemp()94 tracker = Tracker(outdir=outdir, combined=True)95 tracker.add_ok("FakeTestCase", "YESSS!")96 tracker.add_ok("DifferentFakeTestCase", "GOAAL!")97 tracker.generate_tap_reports()98 self.assertFalse(os.path.exists(os.path.join(outdir, "FakeTestCase.tap")))99 self.assertFalse(100 os.path.exists(os.path.join(outdir, "DifferentFakeTestCase.tap"))101 )102 with open(os.path.join(outdir, "testresults.tap"), "r") as f:103 report = f.read()104 expected = inspect.cleandoc(105 """106 TAP version 13107 {header_1}108 ok 1 YESSS!109 {header_2}110 ok 2 GOAAL!111 1..2112 """.format(113 header_1=self._make_header("FakeTestCase"),114 header_2=self._make_header("DifferentFakeTestCase"),115 )116 )117 self.assertEqual(report.strip(), expected)118 def test_tracker_does_not_stream_by_default(self):119 tracker = Tracker()120 self.assertFalse(tracker.streaming)121 def test_tracker_has_stream(self):122 tracker = Tracker()123 self.assertTrue(tracker.stream is None)124 @mock.patch("tap.tracker.ENABLE_VERSION_13", False)125 def test_add_ok_writes_to_stream_while_streaming(self):126 stream = StringIO()127 tracker = Tracker(streaming=True, stream=stream)128 tracker.add_ok("FakeTestCase", "YESSS!")129 tracker.add_ok("AnotherTestCase", "Sure.")130 expected = inspect.cleandoc(131 """{header_1}132 ok 1 YESSS!133 {header_2}134 ok 2 Sure.135 """.format(136 header_1=self._make_header("FakeTestCase"),137 header_2=self._make_header("AnotherTestCase"),138 )139 )140 self.assertEqual(stream.getvalue().strip(), expected)141 @mock.patch("tap.tracker.ENABLE_VERSION_13", False)142 def test_add_not_ok_writes_to_stream_while_streaming(self):143 stream = StringIO()144 tracker = Tracker(streaming=True, stream=stream)145 tracker.add_not_ok("FakeTestCase", "YESSS!")146 expected = inspect.cleandoc(147 """{header}148 not ok 1 YESSS!149 """.format(150 header=self._make_header("FakeTestCase")151 )152 )153 self.assertEqual(stream.getvalue().strip(), expected)154 @mock.patch("tap.tracker.ENABLE_VERSION_13", False)155 def test_add_skip_writes_to_stream_while_streaming(self):156 stream = StringIO()157 tracker = Tracker(streaming=True, stream=stream)158 tracker.add_skip("FakeTestCase", "YESSS!", "a reason")159 expected = inspect.cleandoc(160 """{header}161 ok 1 YESSS! # SKIP a reason162 """.format(163 header=self._make_header("FakeTestCase")164 )165 )166 self.assertEqual(stream.getvalue().strip(), expected)167 def test_streaming_does_not_write_files(self):168 outdir = tempfile.mkdtemp()169 stream = StringIO()170 tracker = Tracker(outdir=outdir, streaming=True, stream=stream)171 tracker.add_ok("FakeTestCase", "YESSS!")172 tracker.generate_tap_reports()173 self.assertFalse(os.path.exists(os.path.join(outdir, "FakeTestCase.tap")))174 @mock.patch("tap.tracker.ENABLE_VERSION_13", False)175 def test_streaming_writes_plan(self):176 stream = StringIO()177 tracker = Tracker(streaming=True, stream=stream)178 tracker.combined_line_number = 42179 tracker.generate_tap_reports()180 self.assertEqual(stream.getvalue(), "1..42\n")181 @mock.patch("tap.tracker.ENABLE_VERSION_13", False)182 def test_write_plan_first_streaming(self):183 outdir = tempfile.mkdtemp()184 stream = StringIO()185 tracker = Tracker(outdir=outdir, streaming=True, stream=stream)186 tracker.set_plan(123)187 tracker.add_ok("FakeTestCase", "YESSS!")188 tracker.generate_tap_reports()189 self.assertEqual(190 stream.getvalue(),191 "1..123\n{header}\nok 1 YESSS!\n".format(192 header=self._make_header("FakeTestCase")193 ),194 )195 self.assertFalse(os.path.exists(os.path.join(outdir, "FakeTestCase.tap")))196 @mock.patch("tap.tracker.ENABLE_VERSION_13", False)197 def test_write_plan_immediate_streaming(self):198 stream = StringIO()199 Tracker(streaming=True, stream=stream, plan=123)200 self.assertEqual(stream.getvalue(), "1..123\n")201 @mock.patch("tap.tracker.ENABLE_VERSION_13", False)202 def test_write_plan_first_combined(self):203 outdir = tempfile.mkdtemp()204 tracker = Tracker(streaming=False, outdir=outdir, combined=True)205 tracker.set_plan(123)206 tracker.generate_tap_reports()207 with open(os.path.join(outdir, "testresults.tap"), "r") as f:208 lines = f.readlines()209 self.assertEqual(lines[0], "1..123\n")210 @mock.patch("tap.tracker.ENABLE_VERSION_13", False)211 def test_write_plan_first_not_combined(self):212 outdir = tempfile.mkdtemp()213 tracker = Tracker(streaming=False, outdir=outdir, combined=False)214 with self.assertRaises(ValueError):215 tracker.set_plan(123)216 @mock.patch("tap.tracker.ENABLE_VERSION_13", True)217 def test_streaming_writes_tap_version_13(self):218 stream = StringIO()219 tracker = Tracker(streaming=True, stream=stream)220 tracker.add_skip("FakeTestCase", "YESSS!", "a reason")...
plugin.py
Source:plugin.py
...22 super(TAP, self).configure(options, conf)23 if self.enabled:24 self.tracker = Tracker(outdir=options.tap_outdir)25 def finalize(self, results):26 self.tracker.generate_tap_reports()27 def addError(self, test, err):28 err_cls, reason, _ = err29 if err_cls != SkipTest:30 self.tracker.add_not_ok(31 self._cls_name(test), self._description(test))32 else:33 self.tracker.add_skip(34 self._cls_name(test), self._description(test), reason)35 def addFailure(self, test, err):36 self.tracker.add_not_ok(self._cls_name(test), self._description(test))37 def addSuccess(self, test):38 self.tracker.add_ok(self._cls_name(test), self._description(test))39 def _cls_name(self, test):40 # nose masks the true test case name so the real class name is found...
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!