Esempio n. 1
0
    def test_skip_reason_in_message(self):
        junit_report, proc = self.run_with_junitxml_loaded(
            ("scenario", "junitxml", "skip_reason"), "--junit-xml")

        self.assertTestRunOutputMatches(
            proc,
            stderr=r"test \(test_junitxml_skip_reason.Test" + _method_name() +
            r"\) \.* skip",
        )

        exit_status = proc.poll()
        assert exit_status == 0

        with open(junit_report, "r") as fh:
            tree = ET.parse(fh).getroot()

        num_test_cases = len(tree.findall("testcase"))
        assert num_test_cases == 1

        num_skipped = len(tree.find("testcase").findall("skipped"))
        assert num_skipped == 1
        skip_node = tree.find("testcase").find("skipped")
        assert "message" in skip_node.attrib
        skip_message = skip_node.get("message")
        assert skip_message == "test skipped: ohai"
Esempio n. 2
0
 def test_layer_reporter_error_output(self):
     proc = self.runIn(
         "scenario/layers_with_errors",
         "--plugin=nose2.plugins.layers",
         "--layer-reporter",
     )
     expect = [
         r"ERROR: fixture with a value test_err \(test_layers_with_errors.Test"
         + _method_name("test_err")
         + r"\)",
         "ERROR: A test scenario with errors should check for an attribute "
         "that does not exist and raise an error",
         r"FAIL: fixture with a value test_fail \(test_layers_with_errors.Test"
         + _method_name("test_fail")
         + r"\)",
         "FAIL: A test scenario with errors should check that value == 2 "
         "and fail",
     ]
     for line in expect:
         self.assertTestRunOutputMatches(proc, stderr=line)
     self.assertEqual(proc.poll(), 1)
Esempio n. 3
0
 def test_testcase_module_fixtures_report_mp(self):
     proc = self.runIn(
         "scenario/module_fixtures",
         "-v",
         "--plugin=nose2.plugins.mp",
         "-N=2",
         "test_mf_testcase.Test.test_1",
     )
     # report should show correct names for all tests
     self.assertTestRunOutputMatches(
         proc,
         stderr=r"test_1 \(test_mf_testcase.Test" + _method_name("test_1") +
         r"\) ... ok",
     )
     self.assertTestRunOutputMatches(
         proc,
         stderr=r"test_2 \(test_mf_testcase.Test" + _method_name("test_2") +
         r"\) ... ok",
     )
     self.assertTestRunOutputMatches(proc, stderr="Ran 2 tests")
     self.assertEqual(proc.poll(), 0)
Esempio n. 4
0
    def test_report_location_should_be_resilent_to_chdir_in_tests(self):
        junit_report, proc = self.run_with_junitxml_loaded(
            ("scenario", "junitxml", "chdir"), "--junit-xml")

        self.assertTestRunOutputMatches(
            proc,
            stderr=r"test_chdir \(test_junitxml_chdir.Test" +
            _method_name("test_chdir") + r"\) \.* ok",
        )
        self.assertTestRunOutputMatches(proc, stderr="Ran 1 test")
        self.assertEqual(proc.poll(), 0)

        self.assertTrue(
            os.path.isfile(junit_report),
            "junitxml report wasn't found in working directory. "
            "Searched for " + junit_report,
        )
Esempio n. 5
0
    def test_no_report_written_if_loaded_but_not_invoked(self):
        junit_report, proc = self.run_with_junitxml_loaded(
            ("scenario", "junitxml", "happyday"))

        self.assertTestRunOutputMatches(
            proc,
            stderr=r"test \(test_junitxml_happyday.Test" + _method_name() +
            r"\) ... ok",
        )
        self.assertTestRunOutputMatches(proc, stderr="Ran 1 test")
        self.assertEqual(proc.poll(), 0)

        self.assertFalse(
            os.path.isfile(junit_report),
            "junitxml report was found in working directory. "
            "Report file: " + junit_report,
        )
Esempio n. 6
0
    def test_invocation_by_single_dash_option(self):
        junit_report, proc = self.run_with_junitxml_loaded(
            ("scenario", "junitxml", "happyday"), "-X")

        self.assertTestRunOutputMatches(
            proc,
            stderr=r"test \(test_junitxml_happyday.Test" + _method_name() +
            r"\) ... ok",
        )
        self.assertTestRunOutputMatches(proc, stderr="Ran 1 test")
        self.assertEqual(proc.poll(), 0)

        self.assertTrue(
            os.path.isfile(junit_report),
            "junitxml report wasn't found in working directory. "
            "Searched for " + junit_report,
        )
Esempio n. 7
0
    def test_xml_path_override_by_config(self):
        junit_report, proc = self.run_with_junitxml_loaded(
            ("scenario", "junitxml", "non_default_path"),
            "--junit-xml",
            junit_report="a.xml",
        )

        self.assertTestRunOutputMatches(
            proc,
            stderr=r"test \(test_junitxml_non_default_path.Test" +
            _method_name() + r"\) \.* ok",
        )

        exit_status = proc.poll()
        assert exit_status == 0

        self.assertTrue(os.path.isfile(junit_report))
Esempio n. 8
0
    def test_layer_reporter_output(self):
        proc = self.runIn(
            "scenario/layers", "-v", "--plugin=nose2.plugins.layers", "--layer-reporter"
        )
        expect = (
            r"""test \(test_layers.NoLayer"""
            + _method_name()
            + r"""\) ... ok
Base
  test \(test_layers.Outer"""
            + _method_name()
            + r"""\) ... ok
  LayerD
    test \(test_layers.InnerD"""
            + _method_name()
            + r"""\) test with docstring ... ok
  LayerA
    test \(test_layers.InnerA"""
            + _method_name()
            + r"""\) ... ok
  LayerB
    LayerB_1
      test \(test_layers.InnerB_1"""
            + _method_name()
            + r"""\) ... ok
    LayerC
      test \(test_layers.InnerC"""
            + _method_name()
            + r"""\) ... ok
      test2 \(test_layers.InnerC"""
            + _method_name("test2")
            + r"""\) ... ok
    LayerA_1
      test \(test_layers.InnerA_1"""
            + _method_name()
            + r"""\) ... ok"""
        ).split("\n")
        self.assertTestRunOutputMatches(proc, stderr="Ran 8 tests")
        for line in expect:
            self.assertTestRunOutputMatches(proc, stderr=line)
        self.assertEqual(proc.poll(), 0)
Esempio n. 9
0
    def test_report_includes_properties(self):
        work_dir = os.getcwd()
        with open(os.path.join(work_dir, "properties.json"), "w") as fh:
            fh.write('{"PROPERTY_NAME":"PROPERTY_VALUE"}')
        junit_report, proc = self.run_with_junitxml_loaded(
            ("scenario", "junitxml", "with_properties"), "--junit-xml")
        self.assertTestRunOutputMatches(
            proc,
            stderr=r"test \(test_junitxml_with_properties.Test" +
            _method_name() + r"\) \.* ok",
        )
        self.assertEqual(proc.poll(), 0)

        with open(junit_report, "r") as fh:
            tree = ET.parse(fh).getroot()
        self.assertEqual(len(tree.findall("properties")), 1)
        prop = tree.find("properties").find("property")
        assert "name" in prop.attrib
        assert "value" in prop.attrib
        self.assertEqual(prop.get("name"), "PROPERTY_NAME")
        self.assertEqual(prop.get("value"), "PROPERTY_VALUE")
Esempio n. 10
0
    def test_failure_to_write_report(self):
        proc = self.runIn(
            "scenario/junitxml/fail_to_write",
            "--plugin=nose2.plugins.junitxml",
            "-v",
            "--junit-xml",
        )
        self.assertEqual(proc.poll(), 1)

        self.assertTestRunOutputMatches(
            proc,
            stderr=r"test \(test_junitxml_fail_to_write.Test" +
            _method_name() + r"\) \.* ok",
        )

        filename_for_regex = os.path.abspath("/does/not/exist.xml")
        filename_for_regex = filename_for_regex.replace("\\", r"\\\\")
        self.assertTestRunOutputMatches(
            proc,
            stderr=r"Internal Error: runTests aborted: \[Errno 2\] "
            "JUnitXML: Parent folder does not exist for file: "
            "'%s'" % filename_for_regex,
        )
Esempio n. 11
0
    def test_failure_to_read_empty_properties(self):
        proc = self.runIn(
            "scenario/junitxml/empty_properties",
            "--plugin=nose2.plugins.junitxml",
            "-v",
            "--junit-xml",
        )
        self.assertEqual(proc.poll(), 1)

        self.assertTestRunOutputMatches(
            proc,
            stderr=r"test \(test_junitxml_empty_properties.Test" +
            _method_name() + r"\) \.* ok",
        )

        filename_for_regex = os.path.join("empty_properties",
                                          "properties.json")
        filename_for_regex = filename_for_regex.replace("\\", r"\\")
        self.assertTestRunOutputMatches(
            proc,
            stderr="Internal Error: runTests aborted: "
            "JUnitXML: could not decode file: "
            "'.*%s'" % filename_for_regex,
        )
Esempio n. 12
0
from nose2.tests._common import FunctionalTestCase, _method_name, windows_ci_skip

_SUFFIX = """\
----------------------------------------------------------------------
Ran 1 test """

Q_TEST_PATTERN = r"(?<!\.)(?<!ok)" + _SUFFIX
MID_TEST_PATTERN = r"\." + "\n" + _SUFFIX
V_TEST_PATTERN = (
    r"test \(__main__\.Test" + _method_name() + r"\) \.\.\. ok" + "\n\n" + _SUFFIX
)


class TestVerbosity(FunctionalTestCase):
    @windows_ci_skip
    def test_no_modifier(self):
        proc = self.runModuleAsMain("scenario/one_test/tests.py")
        self.assertTestRunOutputMatches(proc, stderr=MID_TEST_PATTERN)

    @windows_ci_skip
    def test_one_v(self):
        proc = self.runModuleAsMain("scenario/one_test/tests.py", "-v")
        self.assertTestRunOutputMatches(proc, stderr=V_TEST_PATTERN)

    @windows_ci_skip
    def test_one_q(self):
        proc = self.runModuleAsMain("scenario/one_test/tests.py", "-q")
        self.assertTestRunOutputMatches(proc, stderr=Q_TEST_PATTERN)

    @windows_ci_skip
    def test_one_q_one_v(self):