Skip to content

Commit

Permalink
Merge pull request #1052 from bluetech/pytester
Browse files Browse the repository at this point in the history
testing: replace `testdir` -> `pytester`
  • Loading branch information
bluetech committed Apr 3, 2024
2 parents d96d87e + d63400e commit 470bc83
Showing 1 changed file with 19 additions and 19 deletions.
38 changes: 19 additions & 19 deletions testing/acceptance_test.py
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

0 comments on commit 470bc83

Please sign in to comment.