summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_doctest.py
diff options
context:
space:
mode:
authorNick Coghlan <ncoghlan@gmail.com>2018-03-25 13:03:10 (GMT)
committerGitHub <noreply@github.com>2018-03-25 13:03:10 (GMT)
commitd5d9e02dd3c6df06a8dd9ce75ee9b52976420a8b (patch)
treec3c02b573a85d3a5caa61e1dd5188ba6bec36392 /Lib/test/test_doctest.py
parentbc77eff8b96be4f035e665ab35c1d06e22f46491 (diff)
downloadcpython-d5d9e02dd3c6df06a8dd9ce75ee9b52976420a8b.zip
cpython-d5d9e02dd3c6df06a8dd9ce75ee9b52976420a8b.tar.gz
cpython-d5d9e02dd3c6df06a8dd9ce75ee9b52976420a8b.tar.bz2
bpo-33053: -m now adds *starting* directory to sys.path (GH-6231)
Historically, -m added the empty string as sys.path zero, meaning it resolved imports against the current working directory, the same way -c and the interactive prompt do. This changes the sys.path initialisation to add the *starting* working directory as sys.path[0] instead, such that changes to the working directory while the program is running will have no effect on imports when using the -m switch.
Diffstat (limited to 'Lib/test/test_doctest.py')
-rw-r--r--Lib/test/test_doctest.py16
1 files changed, 11 insertions, 5 deletions
diff --git a/Lib/test/test_doctest.py b/Lib/test/test_doctest.py
index f0eb528..83941c1 100644
--- a/Lib/test/test_doctest.py
+++ b/Lib/test/test_doctest.py
@@ -9,7 +9,7 @@ import os
import sys
import importlib
import unittest
-
+import tempfile
# NOTE: There are some additional tests relating to interaction with
# zipimport in the test_zipimport_support test module.
@@ -688,10 +688,16 @@ class TestDocTestFinder(unittest.TestCase):
def test_empty_namespace_package(self):
pkg_name = 'doctest_empty_pkg'
- os.mkdir(pkg_name)
- mod = importlib.import_module(pkg_name)
- assert doctest.DocTestFinder().find(mod) == []
- os.rmdir(pkg_name)
+ with tempfile.TemporaryDirectory() as parent_dir:
+ pkg_dir = os.path.join(parent_dir, pkg_name)
+ os.mkdir(pkg_dir)
+ sys.path.append(parent_dir)
+ try:
+ mod = importlib.import_module(pkg_name)
+ finally:
+ support.forget(pkg_name)
+ sys.path.pop()
+ assert doctest.DocTestFinder().find(mod) == []
def test_DocTestParser(): r"""