This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Title: Add temp_dir() and change_cwd() to
Type: enhancement Stage: resolved
Components: Tests Versions: Python 3.3
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: ncoghlan Nosy List: brett.cannon, chris.jerdonek, eric.snow, ezio.melotti, flox, italip, ncoghlan, python-dev, terry.reedy
Priority: normal Keywords: easy, patch

Created on 2012-07-21 21:13 by chris.jerdonek, last changed 2022-04-11 14:57 by admin. This issue is now closed.

File name Uploaded Description Edit
issue-15415-1.patch chris.jerdonek, 2012-07-21 21:53
issue-15415-2.patch chris.jerdonek, 2012-07-21 22:05
issue-15415-3.patch chris.jerdonek, 2012-07-21 23:20 review
issue-15415-4.patch italip, 2013-07-08 06:49
Messages (13)
msg166071 - (view) Author: Chris Jerdonek (chris.jerdonek) * (Python committer) Date: 2012-07-21 21:13
This issue is partly in service to issue 15376, which is to refactor test_runpy's walk_package support code into a common location.

Currently, the temp_cwd() context manager in does two things: it creates a temp directory, and it changes the current working directory.

It would be useful and clearer if exposed these two things as separate context managers.  This will both let us simplify the implementation of temp_cwd() and give us an opportunity to increase code reuse between and test.script_helper.  (Currently, test.script_helper has its own version of temp_dir(), whose functionality overlaps with temp_cwd().)

I will upload a patch shortly with tests.
msg166080 - (view) Author: Chris Jerdonek (chris.jerdonek) * (Python committer) Date: 2012-07-21 21:53
Attaching a patch with tests.
msg166083 - (view) Author: Chris Jerdonek (chris.jerdonek) * (Python committer) Date: 2012-07-21 22:05
Fixing patch so it will apply cleanly.
msg166089 - (view) Author: Chris Jerdonek (chris.jerdonek) * (Python committer) Date: 2012-07-21 23:20
Trying again to have the patch apply cleanly (for the review link).
msg192622 - (view) Author: Indra Talip (italip) * Date: 2013-07-08 06:49
cleaning up patch so that it will apply cleanly after applying patch from issue15494
msg193818 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2013-07-28 12:25
New changeset 4f0034477ba9 by Nick Coghlan in branch '3.3':
Close #15415: Factor out temp dir helpers to

New changeset b20a10c97e08 by Nick Coghlan in branch 'default':
Merge #15415 from 3.3
msg193841 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2013-07-28 21:43
-def temp_cwd(name='tempcwd', quiet=False, path=None):
+def temp_cwd(name='tempcwd', quiet=False):

Since this parameter removal was pushed, the Windows buildbots  consistently have this new error in this Windows-only test.

ERROR: test_empty (test.test_startfile.TestCase)
Traceback (most recent call last):
  File "C:\\3.3.kloth-win64\build\lib\test\", line 26, in test_empty
    with support.temp_cwd(path=path.dirname(sys.executable)):

  File "C:\\3.3.kloth-win64\build\lib\", line 115, in helper
    return _GeneratorContextManager(func, *args, **kwds)
  File "C:\\3.3.kloth-win64\build\lib\", line 37, in __init__
    self.gen = func(*args, **kwds)
TypeError: temp_cwd() got an unexpected keyword argument 'path'
msg193850 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2013-07-29 05:19
New changeset a76693942de3 by Nick Coghlan in branch '3.3':
Attempt to fix #15415 on Windows

New changeset b14308524cff by Nick Coghlan in branch 'default':
Merge #15415 Windows buildbot change from 3.3
msg193851 - (view) Author: Nick Coghlan (ncoghlan) * (Python committer) Date: 2013-07-29 05:21
I did see the Windows buildbot failure, but stopped scanning the log once I saw the intermittent test_signal failure :P

With the more granular API, test_startfile is a better fit for support.change_cwd, so we'll see how that goes on the Windows buildbots.
msg193853 - (view) Author: Nick Coghlan (ncoghlan) * (Python committer) Date: 2013-07-29 07:21
No dice:

Could someone with a Windows build set up try this out?

I'd like to rule out a conflict with the -j setting, since being dependent on the current working directory pretty much rules out being run in parallel with other tests, but I didn't see anything in regrtest that let me say "run this one before fanning out into parallel execution".
msg193854 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2013-07-29 07:52
New changeset 403b038ff075 by Nick Coghlan in branch '3.3':
Third attempt to fix #15415 on Windows

New changeset fa13a159f063 by Nick Coghlan in branch 'default':
Merge #15415 from 3.3 (again)
msg193857 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2013-07-29 08:38
As of this moment, the test has run on one of the two Win7 machines and the xp buildbot. It also runs by itself on my win7 desktop with a fresh pull.
msg193859 - (view) Author: Nick Coghlan (ncoghlan) * (Python committer) Date: 2013-07-29 12:01
While there are some remaining buildbot failures, they don't appear to be related to this issue any more.
Date User Action Args
2022-04-11 14:57:33adminsetgithub: 59620
2013-07-29 12:01:19ncoghlansetstatus: open -> closed
resolution: fixed
messages: + msg193859
2013-07-29 08:38:48terry.reedysetmessages: + msg193857
2013-07-29 07:52:48python-devsetmessages: + msg193854
2013-07-29 07:21:46ncoghlansetmessages: + msg193853
2013-07-29 05:21:40ncoghlansetmessages: + msg193851
2013-07-29 05:19:42python-devsetmessages: + msg193850
2013-07-28 21:43:35terry.reedysetstatus: closed -> open

nosy: + terry.reedy
messages: + msg193841

resolution: fixed -> (no value)
2013-07-28 12:25:48python-devsetstatus: open -> closed

nosy: + python-dev
messages: + msg193818

resolution: fixed
stage: patch review -> resolved
2013-07-08 06:49:17italipsetfiles: + issue-15415-4.patch
nosy: + italip
messages: + msg192622

2012-11-13 06:22:36eric.snowsetnosy: + eric.snow
2012-09-19 14:24:51brett.cannonsetnosy: + brett.cannon
2012-09-19 00:31:49ezio.melottisetnosy: + ezio.melotti, flox
type: enhancement
2012-07-30 10:27:46ncoghlanlinkissue15376 dependencies
2012-07-26 02:18:59ncoghlansetassignee: ncoghlan

nosy: + ncoghlan
2012-07-21 23:20:48chris.jerdoneksetfiles: + issue-15415-3.patch

messages: + msg166089
2012-07-21 22:05:12chris.jerdoneksetfiles: + issue-15415-2.patch

messages: + msg166083
2012-07-21 21:53:29chris.jerdoneksetfiles: + issue-15415-1.patch
keywords: + patch
messages: + msg166080

stage: patch review
2012-07-21 21:13:18chris.jerdonekcreate