diff options
author | Michael Foord <fuzzyman@voidspace.org.uk> | 2010-12-04 01:11:21 (GMT) |
---|---|---|
committer | Michael Foord <fuzzyman@voidspace.org.uk> | 2010-12-04 01:11:21 (GMT) |
commit | 37d120aeb471b3fba7e16550cea5d79ecb901561 (patch) | |
tree | b2b9b0c58d6510c8f3e3c53285cf6b498ad3ec72 /Lib/unittest/main.py | |
parent | e2bb4eb77b24a1870bd7feb15124b7adf1460efe (diff) | |
download | cpython-37d120aeb471b3fba7e16550cea5d79ecb901561.zip cpython-37d120aeb471b3fba7e16550cea5d79ecb901561.tar.gz cpython-37d120aeb471b3fba7e16550cea5d79ecb901561.tar.bz2 |
Issue 10620: Specifying test modules by path instead of module name to 'python -m unittest'
Diffstat (limited to 'Lib/unittest/main.py')
-rw-r--r-- | Lib/unittest/main.py | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/Lib/unittest/main.py b/Lib/unittest/main.py index bd5f2a4..b25d7ac 100644 --- a/Lib/unittest/main.py +++ b/Lib/unittest/main.py @@ -58,7 +58,24 @@ Examples: in MyTestCase """ +def _convert_name(name): + # on Linux / Mac OS X 'foo.PY' is not importable, but on + # Windows it is. Simpler to do a case insensitive match + # a better check would be to check that the name is a + # valid Python module name. + if os.path.isfile(name) and name.lower().endswith('.py'): + if os.path.isabs(name): + rel_path = os.path.relpath(name, os.getcwd()) + if os.path.isabs(rel_path) or rel_path.startswith(os.pardir): + return name + name = rel_path + # on Windows both '\' and '/' are used as path + # separators. Better to replace both than rely on os.path.sep + return name[:-3].replace('\\', '.').replace('/', '.') + return name +def _convert_names(names): + return [_convert_name(name) for name in names] class TestProgram(object): """A command-line program that runs a set of tests; this is primarily @@ -153,7 +170,7 @@ class TestProgram(object): # createTests will load tests from self.module self.testNames = None elif len(args) > 0: - self.testNames = args + self.testNames = _convert_names(args) if __name__ == '__main__': # to support python -m unittest ... self.module = None |