Skip to content

Commit 5591c0b

Browse files
authored
Do not convert --test_filter a.py to a::py (#12)
1 parent 4c2fc98 commit 5591c0b

File tree

1 file changed

+7
-9
lines changed

1 file changed

+7
-9
lines changed

python_pytest/pytest_shim.py

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -46,22 +46,20 @@
4646
args[i] = f"{flag}={undeclared_output_dir}/{arg_split[1]}"
4747

4848
if os.environ.get("TESTBRIDGE_TEST_ONLY"):
49-
# TestClass.test_fn -> TestClass::test_fn
50-
module_name = os.environ.get("TESTBRIDGE_TEST_ONLY").replace(".", "::")
49+
test_filter = os.environ["TESTBRIDGE_TEST_ONLY"]
5150

5251
# If the test filter does not start with a class-like name, then use test filtering instead
53-
# --test_filter=test_fn
54-
if not module_name[0].isupper():
52+
if not test_filter[0].isupper():
53+
# --test_filter=test_module.test_fn or --test_filter=test_module/test_file.py
5554
pytest_args.extend(args)
56-
pytest_args.append("-k={filter}".format(filter=module_name))
55+
pytest_args.append("-k={filter}".format(filter=test_filter))
5756
else:
5857
# --test_filter=TestClass.test_fn
59-
# Add test filter to path-like args
6058
for arg in args:
6159
if not arg.startswith("--"):
62-
# Maybe a src file? Add test class/method selection to it. Not sure if this will work if the
63-
# symbol can't be found in the test file.
64-
arg = "{arg}::{module_fn}".format(arg=arg, module_fn=module_name)
60+
# arg is a src file. Add test class/method selection to it.
61+
# test.py::TestClass::test_fn
62+
arg = "{arg}::{module_fn}".format(arg=arg, module_fn=test_filter.replace(".", "::"))
6563
pytest_args.append(arg)
6664
else:
6765
pytest_args.extend(args)

0 commit comments

Comments
 (0)