bpo-46421: Fix unittest filename evaluation when called as a module (GH-30654)

(cherry picked from commit a0db11b10f)

Co-authored-by: Bader Zaidan <bader@zaidan.pw>
This commit is contained in:
Miss Islington (bot) 2022-03-17 17:00:52 -07:00 committed by GitHub
parent ba76f90192
commit 0b5f99ad1a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 16 additions and 1 deletions

View file

@ -137,6 +137,17 @@ def test_run_module_bug1764407(self):
self.assertTrue(data.find(b'1 loop') != -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):
# Test expected operation of the '-c' switch
# Switch needs an argument