Commit b5a74214 authored by Jérome Perrin's avatar Jérome Perrin

use re.search to filter tests in --run

re.match only find matches where the pattern appears at the beginning of
the string, whereas re.search matches if the pattern appears anywhere in
the string. This is behavior is consistent with pytest, go test and ERP5's
runUnitTest

For more details, see the discussion from nexedi/nxdtest!6 (comment 121409)

/reviewed-on: nexedi/nxdtest!8
parent 1e6a1cc6
...@@ -355,7 +355,7 @@ class LocalTestResult: ...@@ -355,7 +355,7 @@ class LocalTestResult:
self.next += 1 self.next += 1
# --run # --run
if self.run is not None and not re.match(self.run, t.name): if self.run is not None and not re.search(self.run, t.name):
continue continue
test_result_line = LocalTestResultLine() test_result_line = LocalTestResultLine()
......
...@@ -93,7 +93,20 @@ TestCase('TEST2', ['echo', 'TEST2']) ...@@ -93,7 +93,20 @@ TestCase('TEST2', ['echo', 'TEST2'])
""", """,
argv=["nxdtest", "--run", "TEST1"], argv=["nxdtest", "--run", "TEST1"],
) )
captured = capsys.readouterr()
assert "TEST1" in captured.out
assert "TEST2" not in captured.out
# --run uses search
run_nxdtest(
"""\
TestCase('TEST1', ['echo', 'TEST1'])
TestCase('TEST2', ['echo', 'TEST2'])
TestCase('TEST10', ['echo', 'TEST10'])
""",
argv=["nxdtest", "--run", "ST1"],
)
captured = capsys.readouterr() captured = capsys.readouterr()
assert "TEST1" in captured.out assert "TEST1" in captured.out
assert "TEST10" in captured.out
assert "TEST2" not in captured.out assert "TEST2" not in captured.out
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment