Skip to content

testing: replace testdir -> pytester #1052

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 3, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 19 additions & 19 deletions testing/acceptance_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -1372,7 +1372,7 @@ def test_2():


class TestGroupScope:
def test_by_module(self, testdir):
def test_by_module(self, pytester: pytest.Pytester):
test_file = """
import pytest
class TestA:
Expand All @@ -1381,8 +1381,8 @@ class TestA:
def test(self, i):
pass
"""
testdir.makepyfile(test_a=test_file, test_b=test_file)
result = testdir.runpytest("-n2", "--dist=loadgroup", "-v")
pytester.makepyfile(test_a=test_file, test_b=test_file)
result = pytester.runpytest("-n2", "--dist=loadgroup", "-v")
test_a_workers_and_test_count = get_workers_and_test_count_by_prefix(
"test_a.py::TestA", result.outlines
)
Expand All @@ -1403,8 +1403,8 @@ def test(self, i):
== test_b_workers_and_test_count.items()
)

def test_by_class(self, testdir):
testdir.makepyfile(
def test_by_class(self, pytester: pytest.Pytester):
pytester.makepyfile(
test_a="""
import pytest
class TestA:
Expand All @@ -1419,7 +1419,7 @@ def test(self, i):
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.py::TestA", result.outlines
)
Expand All @@ -1440,7 +1440,7 @@ def test(self, i):
== 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 = """
import pytest
@pytest.mark.xdist_group(name="xdist_group")
Expand All @@ -1455,15 +1455,15 @@ def test_1():
def test_2():
pass
"""
testdir.makepyfile(test_a=test_file1, test_b=test_file1, test_c=test_file2)
result = testdir.runpytest("-n2", "--dist=loadgroup", "-v")
pytester.makepyfile(test_a=test_file1, test_b=test_file1, test_c=test_file2)
result = pytester.runpytest("-n2", "--dist=loadgroup", "-v")
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)
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()

def test_with_two_group_names(self, testdir):
def test_with_two_group_names(self, pytester: pytest.Pytester):
test_file = """
import pytest
@pytest.mark.xdist_group(name="group1")
Expand All @@ -1473,8 +1473,8 @@ def test_1():
def test_2():
pass
"""
testdir.makepyfile(test_a=test_file, test_b=test_file)
result = testdir.runpytest("-n2", "--dist=loadgroup", "-v")
pytester.makepyfile(test_a=test_file, test_b=test_file)
result = pytester.runpytest("-n2", "--dist=loadgroup", "-v")
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)
b_1 = get_workers_and_test_count_by_prefix("test_b.py::test_1", result.outlines)
Expand Down Expand Up @@ -1603,13 +1603,13 @@ def test_get_xdist_worker_id(self, fake_request) -> None:
assert xdist.get_xdist_worker_id(fake_request) == "master"


def test_collection_crash(testdir):
p1 = testdir.makepyfile(
def test_collection_crash(pytester: pytest.Pytester):
p1 = pytester.makepyfile(
"""
assert 0
"""
)
result = testdir.runpytest(p1, "-n1")
result = pytester.runpytest(p1, "-n1")
assert result.ret == 1
result.stdout.fnmatch_lines(
[
Expand All @@ -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)."""
testdir.makepyfile(
pytester.makepyfile(
"""
def test():
pass
"""
)
testdir.makeini(
pytester.makeini(
"""
[pytest]
addopts = --dist loadscope
"""
)
result = testdir.runpytest()
result = pytester.runpytest()
assert result.ret == 0