diff options
author | Ned Batchelder <ned@nedbatchelder.com> | 2022-10-02 21:38:58 -0400 |
---|---|---|
committer | Ned Batchelder <ned@nedbatchelder.com> | 2022-10-15 13:58:50 -0400 |
commit | 60fa1306d2b02aa718a21c8e9da10fc063063fe7 (patch) | |
tree | 28fc4c72d78e338445861b5b2f6a905e6153dbaf | |
parent | 8ba6878461690532b0f0a07e90917be0b65efb8c (diff) | |
download | python-coveragepy-git-60fa1306d2b02aa718a21c8e9da10fc063063fe7.tar.gz |
refactor(test): use parametrize instead of loops
-rw-r--r-- | tests/test_files.py | 55 |
1 files changed, 26 insertions, 29 deletions
diff --git a/tests/test_files.py b/tests/test_files.py index b9561eeb..58084f7c 100644 --- a/tests/test_files.py +++ b/tests/test_files.py @@ -357,37 +357,34 @@ class PathAliasesTest(CoverageTest): r'.\mysrc\sub\a.py', ) - def test_windows_on_linux(self, rel_yn): + # Try the paths in both orders. + lin = "*/project/module/" + win = "*\\project\\module\\" + lin_win_paths = [[lin, win], [win, lin]] + + @pytest.mark.parametrize("paths", lin_win_paths) + def test_windows_on_linux(self, paths, rel_yn): # https://github.com/nedbat/coveragepy/issues/618 - lin = "*/project/module/" - win = "*\\project\\module\\" - - # Try the paths in both orders. - for paths in [[lin, win], [win, lin]]: - aliases = PathAliases(relative=rel_yn) - for path in paths: - aliases.add(path, "project/module") - self.assert_mapped( - aliases, - "C:\\a\\path\\somewhere\\coveragepy_test\\project\\module\\tests\\file.py", - "project/module/tests/file.py", - ) - - def test_linux_on_windows(self, rel_yn): + aliases = PathAliases(relative=rel_yn) + for path in paths: + aliases.add(path, "project/module") + self.assert_mapped( + aliases, + "C:\\a\\path\\somewhere\\coveragepy_test\\project\\module\\tests\\file.py", + "project/module/tests/file.py", + ) + + @pytest.mark.parametrize("paths", lin_win_paths) + def test_linux_on_windows(self, paths, rel_yn): # https://github.com/nedbat/coveragepy/issues/618 - lin = "*/project/module/" - win = "*\\project\\module\\" - - # Try the paths in both orders. - for paths in [[lin, win], [win, lin]]: - aliases = PathAliases(relative=rel_yn) - for path in paths: - aliases.add(path, "project\\module") - self.assert_mapped( - aliases, - "C:/a/path/somewhere/coveragepy_test/project/module/tests/file.py", - "project\\module\\tests\\file.py", - ) + aliases = PathAliases(relative=rel_yn) + for path in paths: + aliases.add(path, "project\\module") + self.assert_mapped( + aliases, + "C:/a/path/somewhere/coveragepy_test/project/module/tests/file.py", + "project\\module\\tests\\file.py", + ) def test_multiple_wildcard(self, rel_yn): aliases = PathAliases(relative=rel_yn) |