mirror of https://github.com/python/cpython
bpo-46421: Fix unittest filename evaluation when called as a module (GH-30654)
This commit is contained in:
parent
ac8308d3ea
commit
a0db11b10f
|
@ -166,6 +166,17 @@ class CmdLineTest(unittest.TestCase):
|
||||||
self.assertTrue(data.find(b'1 loop') != -1)
|
self.assertTrue(data.find(b'1 loop') != -1)
|
||||||
self.assertTrue(data.find(b'__main__.Timer') != -1)
|
self.assertTrue(data.find(b'__main__.Timer') != -1)
|
||||||
|
|
||||||
|
def test_relativedir_bug46421(self):
|
||||||
|
# Test `python -m unittest` with a relative directory beginning with ./
|
||||||
|
# Note: We have to switch to the project's top module's directory, as per
|
||||||
|
# the python unittest wiki. We will switch back when we are done.
|
||||||
|
defaultwd = os.getcwd()
|
||||||
|
projectlibpath = os.path.dirname(__file__).removesuffix("test")
|
||||||
|
with os_helper.change_cwd(projectlibpath):
|
||||||
|
# Testing with and without ./
|
||||||
|
assert_python_ok('-m', 'unittest', "test/test_longexp.py")
|
||||||
|
assert_python_ok('-m', 'unittest', "./test/test_longexp.py")
|
||||||
|
|
||||||
def test_run_code(self):
|
def test_run_code(self):
|
||||||
# Test expected operation of the '-c' switch
|
# Test expected operation of the '-c' switch
|
||||||
# Switch needs an argument
|
# Switch needs an argument
|
||||||
|
|
|
@ -40,7 +40,7 @@ def _convert_name(name):
|
||||||
name = rel_path
|
name = rel_path
|
||||||
# on Windows both '\' and '/' are used as path
|
# on Windows both '\' and '/' are used as path
|
||||||
# separators. Better to replace both than rely on os.path.sep
|
# separators. Better to replace both than rely on os.path.sep
|
||||||
return name[:-3].replace('\\', '.').replace('/', '.')
|
return os.path.normpath(name)[:-3].replace('\\', '.').replace('/', '.')
|
||||||
return name
|
return name
|
||||||
|
|
||||||
def _convert_names(names):
|
def _convert_names(names):
|
||||||
|
|
|
@ -1994,6 +1994,7 @@ Masazumi Yoshikawa
|
||||||
Arnaud Ysmal
|
Arnaud Ysmal
|
||||||
Bernard Yue
|
Bernard Yue
|
||||||
Moshe Zadka
|
Moshe Zadka
|
||||||
|
Bader Zaidan
|
||||||
Elias Zamaria
|
Elias Zamaria
|
||||||
Milan Zamazal
|
Milan Zamazal
|
||||||
Artur Zaprzala
|
Artur Zaprzala
|
||||||
|
|
|
@ -0,0 +1,3 @@
|
||||||
|
Fix a unittest issue where if the command was invoked as ``python -m
|
||||||
|
unittest`` and the filename(s) began with a dot (.), a ``ValueError`` is
|
||||||
|
returned.
|
Loading…
Reference in New Issue