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 Anton Lodder
Antony Lee Antony Lee
Arel Cordero Arel Cordero
Ariel Pillemer
Armin Rigo Armin Rigo
Aron Coyle Aron Coyle
Aron Curzon Aron Curzon

View File

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