예제 #1
0
def test_parameterset_for_fail_at_collect(testdir):
    testdir.makeini(
        """
    [pytest]
    {}=fail_at_collect
    """.format(
            EMPTY_PARAMETERSET_OPTION
        )
    )

    config = testdir.parseconfig()
    from _pytest.mark import pytest_configure, get_empty_parameterset_mark
    from _pytest.compat import getfslineno

    pytest_configure(config)

    test_func = all
    func_name = test_func.__name__
    _, func_lineno = getfslineno(test_func)
    expected_errmsg = r"Empty parameter set in '%s' at line %d" % (
        func_name,
        func_lineno,
    )

    with pytest.raises(Collector.CollectError, match=expected_errmsg):
        get_empty_parameterset_mark(config, ["a"], test_func)
예제 #2
0
def test_parameterset_for_fail_at_collect(testdir):
    testdir.makeini("""
    [pytest]
    {}=fail_at_collect
    """.format(EMPTY_PARAMETERSET_OPTION))

    config = testdir.parseconfig()
    from _pytest.mark import pytest_configure, get_empty_parameterset_mark

    pytest_configure(config)

    with pytest.raises(
            Collector.CollectError,
            match=r"Empty parameter set in 'pytest_configure' at line \d\d+",
    ):
        get_empty_parameterset_mark(config, ["a"], pytest_configure)

    p1 = testdir.makepyfile("""
        import pytest

        @pytest.mark.parametrize("empty", [])
        def test():
            pass
        """)
    result = testdir.runpytest(str(p1))
    result.stdout.fnmatch_lines([
        "collected 0 items / 1 error",
        "* ERROR collecting test_parameterset_for_fail_at_collect.py *",
        "Empty parameter set in 'test' at line 3",
        "*= 1 error in *",
    ])
    assert result.ret == ExitCode.INTERRUPTED
예제 #3
0
def test_parameterset_for_parametrize_marks(
    pytester: Pytester, mark: Optional[str]
) -> None:
    if mark is not None:
        pytester.makeini(
            """
        [pytest]
        {}={}
        """.format(
                EMPTY_PARAMETERSET_OPTION, mark
            )
        )

    config = pytester.parseconfig()
    from _pytest.mark import pytest_configure, get_empty_parameterset_mark

    pytest_configure(config)
    result_mark = get_empty_parameterset_mark(config, ["a"], all)
    if mark in (None, ""):
        # normalize to the requested name
        mark = "skip"
    assert result_mark.name == mark
    assert result_mark.kwargs["reason"].startswith("got empty parameter set ")
    if mark == "xfail":
        assert result_mark.kwargs.get("run") is False
예제 #4
0
def test_parameterset_for_fail_at_collect(testdir):
    testdir.makeini(
        """
    [pytest]
    {}=fail_at_collect
    """.format(
            EMPTY_PARAMETERSET_OPTION
        )
    )

    config = testdir.parseconfig()
    from _pytest.mark import pytest_configure, get_empty_parameterset_mark

    pytest_configure(config)

    with pytest.raises(
        Collector.CollectError,
        match=r"Empty parameter set in 'pytest_configure' at line \d\d+",
    ):
        get_empty_parameterset_mark(config, ["a"], pytest_configure)

    p1 = testdir.makepyfile(
        """
        import pytest

        @pytest.mark.parametrize("empty", [])
        def test():
            pass
        """
    )
    result = testdir.runpytest(str(p1))
    result.stdout.fnmatch_lines(
        [
            "collected 0 items / 1 errors",
            "* ERROR collecting test_parameterset_for_fail_at_collect.py *",
            "Empty parameter set in 'test' at line 3",
            "*= 1 error in *",
        ]
    )
    assert result.ret == EXIT_INTERRUPTED
예제 #5
0
def test_parameterset_for_parametrize_marks(testdir, mark):
    if mark is not None:
        testdir.makeini("[pytest]\n{}={}".format(EMPTY_PARAMETERSET_OPTION,
                                                 mark))

    config = testdir.parseconfig()
    from _pytest.mark import pytest_configure, get_empty_parameterset_mark
    pytest_configure(config)
    result_mark = get_empty_parameterset_mark(config, ['a'], all)
    if mark in (None, ''):
        # normalize to the requested name
        mark = 'skip'
    assert result_mark.name == mark
    assert result_mark.kwargs['reason'].startswith("got empty parameter set ")
    if mark == 'xfail':
        assert result_mark.kwargs.get('run') is False
예제 #6
0
파일: test_mark.py 프로젝트: Coder206/servo
def test_parameterset_for_parametrize_marks(testdir, mark):
    if mark is not None:
        testdir.makeini("[pytest]\n{}={}".format(EMPTY_PARAMETERSET_OPTION, mark))

    config = testdir.parseconfig()
    from _pytest.mark import pytest_configure, get_empty_parameterset_mark

    pytest_configure(config)
    result_mark = get_empty_parameterset_mark(config, ["a"], all)
    if mark in (None, ""):
        # normalize to the requested name
        mark = "skip"
    assert result_mark.name == mark
    assert result_mark.kwargs["reason"].startswith("got empty parameter set ")
    if mark == "xfail":
        assert result_mark.kwargs.get("run") is False