pytest-dev#7942 test_runner_xunit.py (#7964)

This commit is contained in:
Ariel Pillemer 2020-10-31 20:08:11 +09:30 committed by GitHub
parent 3c7eb5a398
commit a7e38c5c61
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 30 additions and 28 deletions

View File

@ -32,6 +32,7 @@ Anthony Sottile
Anton Lodder
Antony Lee
Arel Cordero
Ariel Pillemer
Armin Rigo
Aron Coyle
Aron Curzon

View File

@ -2,10 +2,11 @@
from typing import List
import pytest
from _pytest.pytester import Pytester
def test_module_and_function_setup(testdir):
reprec = testdir.inline_runsource(
def test_module_and_function_setup(pytester: Pytester) -> None:
reprec = pytester.inline_runsource(
"""
modlevel = []
def setup_module(module):
@ -37,8 +38,8 @@ def test_module_and_function_setup(testdir):
assert rep.passed
def test_module_setup_failure_no_teardown(testdir):
reprec = testdir.inline_runsource(
def test_module_setup_failure_no_teardown(pytester: Pytester) -> None:
reprec = pytester.inline_runsource(
"""
values = []
def setup_module(module):
@ -57,8 +58,8 @@ def test_module_setup_failure_no_teardown(testdir):
assert calls[0].item.module.values == [1]
def test_setup_function_failure_no_teardown(testdir):
reprec = testdir.inline_runsource(
def test_setup_function_failure_no_teardown(pytester: Pytester) -> None:
reprec = pytester.inline_runsource(
"""
modlevel = []
def setup_function(function):
@ -76,8 +77,8 @@ def test_setup_function_failure_no_teardown(testdir):
assert calls[0].item.module.modlevel == [1]
def test_class_setup(testdir):
reprec = testdir.inline_runsource(
def test_class_setup(pytester: Pytester) -> None:
reprec = pytester.inline_runsource(
"""
class TestSimpleClassSetup(object):
clslevel = []
@ -102,8 +103,8 @@ def test_class_setup(testdir):
reprec.assertoutcome(passed=1 + 2 + 1)
def test_class_setup_failure_no_teardown(testdir):
reprec = testdir.inline_runsource(
def test_class_setup_failure_no_teardown(pytester: Pytester) -> None:
reprec = pytester.inline_runsource(
"""
class TestSimpleClassSetup(object):
clslevel = []
@ -123,8 +124,8 @@ def test_class_setup_failure_no_teardown(testdir):
reprec.assertoutcome(failed=1, passed=1)
def test_method_setup(testdir):
reprec = testdir.inline_runsource(
def test_method_setup(pytester: Pytester) -> None:
reprec = pytester.inline_runsource(
"""
class TestSetupMethod(object):
def setup_method(self, meth):
@ -142,8 +143,8 @@ def test_method_setup(testdir):
reprec.assertoutcome(passed=2)
def test_method_setup_failure_no_teardown(testdir):
reprec = testdir.inline_runsource(
def test_method_setup_failure_no_teardown(pytester: Pytester) -> None:
reprec = pytester.inline_runsource(
"""
class TestMethodSetup(object):
clslevel = []
@ -164,8 +165,8 @@ def test_method_setup_failure_no_teardown(testdir):
reprec.assertoutcome(failed=1, passed=1)
def test_method_setup_uses_fresh_instances(testdir):
reprec = testdir.inline_runsource(
def test_method_setup_uses_fresh_instances(pytester: Pytester) -> None:
reprec = pytester.inline_runsource(
"""
class TestSelfState1(object):
memory = []
@ -179,8 +180,8 @@ def test_method_setup_uses_fresh_instances(testdir):
reprec.assertoutcome(passed=2, failed=0)
def test_setup_that_skips_calledagain(testdir):
p = testdir.makepyfile(
def test_setup_that_skips_calledagain(pytester: Pytester) -> None:
p = pytester.makepyfile(
"""
import pytest
def setup_module(mod):
@ -191,12 +192,12 @@ def test_setup_that_skips_calledagain(testdir):
pass
"""
)
reprec = testdir.inline_run(p)
reprec = pytester.inline_run(p)
reprec.assertoutcome(skipped=2)
def test_setup_fails_again_on_all_tests(testdir):
p = testdir.makepyfile(
def test_setup_fails_again_on_all_tests(pytester: Pytester) -> None:
p = pytester.makepyfile(
"""
import pytest
def setup_module(mod):
@ -207,12 +208,12 @@ def test_setup_fails_again_on_all_tests(testdir):
pass
"""
)
reprec = testdir.inline_run(p)
reprec = pytester.inline_run(p)
reprec.assertoutcome(failed=2)
def test_setup_funcarg_setup_when_outer_scope_fails(testdir):
p = testdir.makepyfile(
def test_setup_funcarg_setup_when_outer_scope_fails(pytester: Pytester) -> None:
p = pytester.makepyfile(
"""
import pytest
def setup_module(mod):
@ -226,7 +227,7 @@ def test_setup_funcarg_setup_when_outer_scope_fails(testdir):
pass
"""
)
result = testdir.runpytest(p)
result = pytester.runpytest(p)
result.stdout.fnmatch_lines(
[
"*function1*",
@ -241,7 +242,7 @@ def test_setup_funcarg_setup_when_outer_scope_fails(testdir):
@pytest.mark.parametrize("arg", ["", "arg"])
def test_setup_teardown_function_level_with_optional_argument(
testdir, monkeypatch, arg: str,
pytester: Pytester, monkeypatch, arg: str,
) -> None:
"""Parameter to setup/teardown xunit-style functions parameter is now optional (#1728)."""
import sys
@ -250,7 +251,7 @@ def test_setup_teardown_function_level_with_optional_argument(
monkeypatch.setattr(
sys, "trace_setups_teardowns", trace_setups_teardowns, raising=False
)
p = testdir.makepyfile(
p = pytester.makepyfile(
"""
import pytest
import sys
@ -276,7 +277,7 @@ def test_setup_teardown_function_level_with_optional_argument(
arg=arg
)
)
result = testdir.inline_run(p)
result = pytester.inline_run(p)
result.assertoutcome(passed=4)
expected = [