Merge pull request #1052 from bluetech/pytester

testing: replace `testdir` -> `pytester`
This commit is contained in:
Ran Benita
2024-04-04 00:09:41 +03:00
committed by GitHub

View File

@@ -1372,7 +1372,7 @@ class TestFileScope:
class TestGroupScope: class TestGroupScope:
def test_by_module(self, testdir): def test_by_module(self, pytester: pytest.Pytester):
test_file = """ test_file = """
import pytest import pytest
class TestA: class TestA:
@@ -1381,8 +1381,8 @@ class TestGroupScope:
def test(self, i): def test(self, i):
pass pass
""" """
testdir.makepyfile(test_a=test_file, test_b=test_file) pytester.makepyfile(test_a=test_file, test_b=test_file)
result = testdir.runpytest("-n2", "--dist=loadgroup", "-v") result = pytester.runpytest("-n2", "--dist=loadgroup", "-v")
test_a_workers_and_test_count = get_workers_and_test_count_by_prefix( test_a_workers_and_test_count = get_workers_and_test_count_by_prefix(
"test_a.py::TestA", result.outlines "test_a.py::TestA", result.outlines
) )
@@ -1403,8 +1403,8 @@ class TestGroupScope:
== test_b_workers_and_test_count.items() == test_b_workers_and_test_count.items()
) )
def test_by_class(self, testdir): def test_by_class(self, pytester: pytest.Pytester):
testdir.makepyfile( pytester.makepyfile(
test_a=""" test_a="""
import pytest import pytest
class TestA: class TestA:
@@ -1419,7 +1419,7 @@ class TestGroupScope:
pass pass
""" """
) )
result = testdir.runpytest("-n2", "--dist=loadgroup", "-v") result = pytester.runpytest("-n2", "--dist=loadgroup", "-v")
test_a_workers_and_test_count = get_workers_and_test_count_by_prefix( test_a_workers_and_test_count = get_workers_and_test_count_by_prefix(
"test_a.py::TestA", result.outlines "test_a.py::TestA", result.outlines
) )
@@ -1440,7 +1440,7 @@ class TestGroupScope:
== test_b_workers_and_test_count.items() == test_b_workers_and_test_count.items()
) )
def test_module_single_start(self, testdir): def test_module_single_start(self, pytester: pytest.Pytester):
test_file1 = """ test_file1 = """
import pytest import pytest
@pytest.mark.xdist_group(name="xdist_group") @pytest.mark.xdist_group(name="xdist_group")
@@ -1455,15 +1455,15 @@ class TestGroupScope:
def test_2(): def test_2():
pass pass
""" """
testdir.makepyfile(test_a=test_file1, test_b=test_file1, test_c=test_file2) pytester.makepyfile(test_a=test_file1, test_b=test_file1, test_c=test_file2)
result = testdir.runpytest("-n2", "--dist=loadgroup", "-v") result = pytester.runpytest("-n2", "--dist=loadgroup", "-v")
a = get_workers_and_test_count_by_prefix("test_a.py::test", result.outlines) a = get_workers_and_test_count_by_prefix("test_a.py::test", result.outlines)
b = get_workers_and_test_count_by_prefix("test_b.py::test", result.outlines) b = get_workers_and_test_count_by_prefix("test_b.py::test", result.outlines)
c = get_workers_and_test_count_by_prefix("test_c.py::test_2", result.outlines) c = get_workers_and_test_count_by_prefix("test_c.py::test_2", result.outlines)
assert a.keys() == b.keys() and b.keys() == c.keys() assert a.keys() == b.keys() and b.keys() == c.keys()
def test_with_two_group_names(self, testdir): def test_with_two_group_names(self, pytester: pytest.Pytester):
test_file = """ test_file = """
import pytest import pytest
@pytest.mark.xdist_group(name="group1") @pytest.mark.xdist_group(name="group1")
@@ -1473,8 +1473,8 @@ class TestGroupScope:
def test_2(): def test_2():
pass pass
""" """
testdir.makepyfile(test_a=test_file, test_b=test_file) pytester.makepyfile(test_a=test_file, test_b=test_file)
result = testdir.runpytest("-n2", "--dist=loadgroup", "-v") result = pytester.runpytest("-n2", "--dist=loadgroup", "-v")
a_1 = get_workers_and_test_count_by_prefix("test_a.py::test_1", result.outlines) a_1 = get_workers_and_test_count_by_prefix("test_a.py::test_1", result.outlines)
a_2 = get_workers_and_test_count_by_prefix("test_a.py::test_2", result.outlines) a_2 = get_workers_and_test_count_by_prefix("test_a.py::test_2", result.outlines)
b_1 = get_workers_and_test_count_by_prefix("test_b.py::test_1", result.outlines) b_1 = get_workers_and_test_count_by_prefix("test_b.py::test_1", result.outlines)
@@ -1603,13 +1603,13 @@ class TestAPI:
assert xdist.get_xdist_worker_id(fake_request) == "master" assert xdist.get_xdist_worker_id(fake_request) == "master"
def test_collection_crash(testdir): def test_collection_crash(pytester: pytest.Pytester):
p1 = testdir.makepyfile( p1 = pytester.makepyfile(
""" """
assert 0 assert 0
""" """
) )
result = testdir.runpytest(p1, "-n1") result = pytester.runpytest(p1, "-n1")
assert result.ret == 1 assert result.ret == 1
result.stdout.fnmatch_lines( result.stdout.fnmatch_lines(
[ [
@@ -1622,19 +1622,19 @@ def test_collection_crash(testdir):
) )
def test_dist_in_addopts(testdir): def test_dist_in_addopts(pytester: pytest.Pytester):
"""Users can set a default distribution in the configuration file (#789).""" """Users can set a default distribution in the configuration file (#789)."""
testdir.makepyfile( pytester.makepyfile(
""" """
def test(): def test():
pass pass
""" """
) )
testdir.makeini( pytester.makeini(
""" """
[pytest] [pytest]
addopts = --dist loadscope addopts = --dist loadscope
""" """
) )
result = testdir.runpytest() result = pytester.runpytest()
assert result.ret == 0 assert result.ret == 0