fix(pytest): handle parameterized tests without pytest discovery

Only emits position IDs with parameters when pytest discovery is enabled

See #36 and #59
This commit is contained in:
Rónán Carrigan
2023-12-20 18:49:01 +00:00
parent 48bf141103
commit 27a2676aa0
5 changed files with 59 additions and 28 deletions

View File

@@ -12,11 +12,11 @@ class TestRunner(str, Enum):
DJANGO = "django"
def get_adapter(runner: TestRunner) -> NeotestAdapter:
def get_adapter(runner: TestRunner, emit_parameterized_ids: bool) -> NeotestAdapter:
if runner == TestRunner.PYTEST:
from .pytest import PytestNeotestAdapter
return PytestNeotestAdapter()
return PytestNeotestAdapter(emit_parameterized_ids)
elif runner == TestRunner.UNITTEST:
from .unittest import UnittestNeotestAdapter
@@ -42,6 +42,11 @@ parser.add_argument(
required=True,
help="File to stream result JSON to",
)
parser.add_argument(
"--emit-parameterized-ids",
action="store_true",
help="Emit parameterized test ids (pytest only)",
)
parser.add_argument("args", nargs="*")
@@ -49,11 +54,12 @@ def main(argv: List[str]):
if "--pytest-collect" in argv:
argv.remove("--pytest-collect")
from .pytest import collect
collect(argv)
return
args = parser.parse_args(argv)
adapter = get_adapter(TestRunner(args.runner))
adapter = get_adapter(TestRunner(args.runner), args.emit_parameterized_ids)
with open(args.stream_file, "w") as stream_file: