예제 #1
0
def test_setup_inheritance_skipping(
    pytester: Pytester, test_name, expected_outcome
) -> None:
    """Issue #4700"""
    pytester.copy_example(f"unittest/{test_name}")
    result = pytester.runpytest()
    result.stdout.fnmatch_lines([f"* {expected_outcome} in *"])
예제 #2
0
def test_group_warnings_by_message(pytester: Pytester) -> None:
    pytester.copy_example("warnings/test_group_warnings_by_message.py")
    result = pytester.runpytest()
    result.stdout.fnmatch_lines(
        [
            "*== %s ==*" % WARNINGS_SUMMARY_HEADER,
            "test_group_warnings_by_message.py::test_foo[[]0[]]",
            "test_group_warnings_by_message.py::test_foo[[]1[]]",
            "test_group_warnings_by_message.py::test_foo[[]2[]]",
            "test_group_warnings_by_message.py::test_foo[[]3[]]",
            "test_group_warnings_by_message.py::test_foo[[]4[]]",
            "test_group_warnings_by_message.py::test_foo_1",
            "  */test_group_warnings_by_message.py:*: UserWarning: foo",
            "    warnings.warn(UserWarning(msg))",
            "",
            "test_group_warnings_by_message.py::test_bar[[]0[]]",
            "test_group_warnings_by_message.py::test_bar[[]1[]]",
            "test_group_warnings_by_message.py::test_bar[[]2[]]",
            "test_group_warnings_by_message.py::test_bar[[]3[]]",
            "test_group_warnings_by_message.py::test_bar[[]4[]]",
            "  */test_group_warnings_by_message.py:*: UserWarning: bar",
            "    warnings.warn(UserWarning(msg))",
            "",
            "-- Docs: *",
            "*= 11 passed, 11 warnings *",
        ],
        consecutive=True,
    )
예제 #3
0
def test_asynctest_support(pytester: Pytester) -> None:
    """Check asynctest support (#7110)"""
    pytest.importorskip("asynctest")

    pytester.copy_example("unittest/test_unittest_asynctest.py")
    reprec = pytester.inline_run()
    reprec.assertoutcome(failed=1, passed=2)
예제 #4
0
def test_error_message_with_parametrized_fixtures(pytester: Pytester) -> None:
    pytester.copy_example(
        "unittest/test_parametrized_fixture_error_message.py")
    result = pytester.runpytest()
    result.stdout.fnmatch_lines([
        "*test_two does not support fixtures*",
        "*TestSomethingElse::test_two",
        "*Function type: TestCaseFunction",
    ])
예제 #5
0
def test_plain_unittest_does_not_support_async(pytester: Pytester) -> None:
    """Async functions in plain unittest.TestCase subclasses are not supported without plugins.

    This test exists here to avoid introducing this support by accident, leading users
    to expect that it works, rather than doing so intentionally as a feature.

    See https://github.com/pytest-dev/pytest-asyncio/issues/180 for more context.
    """
    pytester.copy_example("unittest/test_unittest_plain_async.py")
    result = pytester.runpytest_subprocess()
    if hasattr(sys, "pypy_version_info"):
        # in PyPy we can't reliable get the warning about the coroutine not being awaited,
        # because it depends on the coroutine being garbage collected; given that
        # we are running in a subprocess, that's difficult to enforce
        expected_lines = ["*1 passed*"]
    else:
        expected_lines = [
            "*RuntimeWarning: coroutine * was never awaited",
            "*1 passed*",
        ]
    result.stdout.fnmatch_lines(expected_lines)
예제 #6
0
def test_group_warnings_by_message_summary(pytester: Pytester) -> None:
    pytester.copy_example("warnings/test_group_warnings_by_message_summary")
    pytester.syspathinsert()
    result = pytester.runpytest()
    result.stdout.fnmatch_lines(
        [
            "*== %s ==*" % WARNINGS_SUMMARY_HEADER,
            "test_1.py: 21 warnings",
            "test_2.py: 1 warning",
            "  */test_1.py:7: UserWarning: foo",
            "    warnings.warn(UserWarning(msg))",
            "",
            "test_1.py: 20 warnings",
            "  */test_1.py:7: UserWarning: bar",
            "    warnings.warn(UserWarning(msg))",
            "",
            "-- Docs: *",
            "*= 42 passed, 42 warnings *",
        ],
        consecutive=True,
    )
예제 #7
0
 def test_main_py_does_not_cause_import_errors(self, pytester: Pytester):
     p = pytester.copy_example("doctest/main_py")
     result = pytester.runpytest(p, "--doctest-modules")
     result.stdout.fnmatch_lines(
         ["*collected 2 items*", "*1 failed, 1 passed*"])
예제 #8
0
 def test_issue88_initial_file_multinodes(self, pytester: Pytester) -> None:
     pytester.copy_example("issue88_initial_file_multinodes")
     p = pytester.makepyfile("def test_hello(): pass")
     result = pytester.runpytest(p, "--collect-only")
     result.stdout.fnmatch_lines(["*MyFile*test_issue88*", "*Module*test_issue88*"])
예제 #9
0
 def test_config_error(self, pytester: Pytester) -> None:
     pytester.copy_example("conftest_usageerror/conftest.py")
     result = pytester.runpytest(pytester.path)
     assert result.ret == ExitCode.USAGE_ERROR
     result.stderr.fnmatch_lines(["*ERROR: hello"])
     result.stdout.fnmatch_lines(["*pytest_unconfigure_called"])
예제 #10
0
def test_fixture_mock_integration(pytester: Pytester) -> None:
    """Test that decorators applied to fixture are left working (#3774)"""
    p = pytester.copy_example("acceptance/fixture_mock_integration.py")
    result = pytester.runpytest(p)
    result.stdout.fnmatch_lines(["*1 passed*"])
예제 #11
0
def test_keyword_option_considers_mark(pytester: Pytester) -> None:
    pytester.copy_example("marks/marks_considered_keywords")
    rec = pytester.inline_run("-k", "foo")
    passed = rec.listoutcomes()[0]
    assert len(passed) == 1
def test_disabled(pytester: Pytester, read_conftest: str) -> None:
    pytester.makeconftest(read_conftest)
    pytester.copy_example()
    pytester.runpytest().assert_outcomes(passed=1)
def test_enabled(pytester: Pytester, read_conftest: str) -> None:
    pytester.makeconftest(read_conftest)
    pytester.copy_example()
    pytester.runpytest('--blockage-httpx').assert_outcomes(passed=4)
예제 #14
0
def test_519(pytester: Pytester) -> None:
    pytester.copy_example("issue_519.py")
    res = pytester.runpytest("issue_519.py")
    res.assert_outcomes(passed=8)
예제 #15
0
def test_async_support(pytester: Pytester) -> None:
    pytest.importorskip("unittest.async_case")

    pytester.copy_example("unittest/test_unittest_asyncio.py")
    reprec = pytester.inline_run()
    reprec.assertoutcome(failed=1, passed=2)
예제 #16
0
def test_package_collection_init_given_as_argument(pytester: Pytester) -> None:
    """Regression test for #3749"""
    p = pytester.copy_example("collect/package_init_given_as_arg")
    result = pytester.runpytest(p / "pkg" / "__init__.py")
    result.stdout.fnmatch_lines(["*1 passed*"])
예제 #17
0
def test_package_collection_infinite_recursion(pytester: Pytester) -> None:
    pytester.copy_example("collect/package_infinite_recursion")
    result = pytester.runpytest()
    result.stdout.fnmatch_lines(["*1 passed*"])
예제 #18
0
def test_tmp_path_fixture(pytester: Pytester) -> None:
    p = pytester.copy_example("tmpdir/tmp_path_fixture.py")
    results = pytester.runpytest(p)
    results.stdout.fnmatch_lines(["*1 passed*"])
예제 #19
0
def test_510(pytester: Pytester) -> None:
    pytester.copy_example("issue_519.py")
    pytester.runpytest("issue_519.py")