forked from pantsbuild/pants
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow for automatic use of
pytest-xdist
(pantsbuild#16499)
Closes pantsbuild#15026. [ci skip-rust] [ci skip-build-wheels] Co-authored-by: Stu Hood <[email protected]>
- Loading branch information
Showing
8 changed files
with
529 additions
and
182 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
src/python/pants/backend/python/goals/pytest_runner_test.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
# Copyright 2022 Pants project contributors (see CONTRIBUTORS.md). | ||
# Licensed under the Apache License, Version 2.0 (see LICENSE). | ||
|
||
from pants.backend.python.goals.pytest_runner import _count_pytest_tests | ||
from pants.engine.fs import DigestContents, FileContent | ||
|
||
EXAMPLE_TEST1 = b""" | ||
def test_foo(): | ||
pass | ||
def test_bar(): | ||
pass | ||
""" | ||
|
||
EXAMPLE_TEST2 = b""" | ||
class TestStuff(TestCase): | ||
def test_baz(): | ||
pass | ||
def testHelper(): | ||
pass | ||
""" | ||
|
||
|
||
def test_count_pytest_tests_empty() -> None: | ||
digest_contents = DigestContents([FileContent(path="tests/test_empty.py", content=b"")]) | ||
test_count = _count_pytest_tests(digest_contents) | ||
assert test_count == 0 | ||
|
||
|
||
def test_count_pytest_tests_methods() -> None: | ||
digest_contents = DigestContents( | ||
[FileContent(path="tests/test_example1.py", content=EXAMPLE_TEST1)] | ||
) | ||
test_count = _count_pytest_tests(digest_contents) | ||
assert test_count == 2 | ||
|
||
|
||
def test_count_pytest_tests_in_class() -> None: | ||
digest_contents = DigestContents( | ||
[FileContent(path="tests/test_example1.py", content=EXAMPLE_TEST2)] | ||
) | ||
test_count = _count_pytest_tests(digest_contents) | ||
assert test_count == 1 | ||
|
||
|
||
def test_count_pytest_tests_multiple() -> None: | ||
digest_contents = DigestContents( | ||
[ | ||
FileContent(path="tests/test_empty.py", content=b""), | ||
FileContent(path="tests/test_example1.py", content=EXAMPLE_TEST1), | ||
FileContent(path="tests/test_example2.py", content=EXAMPLE_TEST2), | ||
] | ||
) | ||
test_count = _count_pytest_tests(digest_contents) | ||
assert test_count == 3 |
Oops, something went wrong.