pytester: use per test tmproot
This commit is contained in:
		
							parent
							
								
									4a436b5470
								
							
						
					
					
						commit
						b82d6f7a0b
					
				| 
						 | 
					@ -496,6 +496,8 @@ class Testdir(object):
 | 
				
			||||||
        self._mod_collections = WeakKeyDictionary()
 | 
					        self._mod_collections = WeakKeyDictionary()
 | 
				
			||||||
        name = request.function.__name__
 | 
					        name = request.function.__name__
 | 
				
			||||||
        self.tmpdir = tmpdir_factory.mktemp(name, numbered=True)
 | 
					        self.tmpdir = tmpdir_factory.mktemp(name, numbered=True)
 | 
				
			||||||
 | 
					        self.test_tmproot = tmpdir_factory.mktemp("tmp-" + name, numbered=True)
 | 
				
			||||||
 | 
					        os.environ["PYTEST_DEBUG_TEMPROOT"] = str(self.test_tmproot)
 | 
				
			||||||
        self.plugins = []
 | 
					        self.plugins = []
 | 
				
			||||||
        self._cwd_snapshot = CwdSnapshot()
 | 
					        self._cwd_snapshot = CwdSnapshot()
 | 
				
			||||||
        self._sys_path_snapshot = SysPathsSnapshot()
 | 
					        self._sys_path_snapshot = SysPathsSnapshot()
 | 
				
			||||||
| 
						 | 
					@ -522,6 +524,7 @@ class Testdir(object):
 | 
				
			||||||
        self._sys_modules_snapshot.restore()
 | 
					        self._sys_modules_snapshot.restore()
 | 
				
			||||||
        self._sys_path_snapshot.restore()
 | 
					        self._sys_path_snapshot.restore()
 | 
				
			||||||
        self._cwd_snapshot.restore()
 | 
					        self._cwd_snapshot.restore()
 | 
				
			||||||
 | 
					        del os.environ["PYTEST_DEBUG_TEMPROOT"]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def __take_sys_modules_snapshot(self):
 | 
					    def __take_sys_modules_snapshot(self):
 | 
				
			||||||
        # some zope modules used by twisted-related tests keep internal state
 | 
					        # some zope modules used by twisted-related tests keep internal state
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1,6 +1,7 @@
 | 
				
			||||||
""" support for providing temporary directories to test functions.  """
 | 
					""" support for providing temporary directories to test functions.  """
 | 
				
			||||||
from __future__ import absolute_import, division, print_function
 | 
					from __future__ import absolute_import, division, print_function
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import os
 | 
				
			||||||
import re
 | 
					import re
 | 
				
			||||||
import pytest
 | 
					import pytest
 | 
				
			||||||
import py
 | 
					import py
 | 
				
			||||||
| 
						 | 
					@ -51,7 +52,8 @@ class TempPathFactory(object):
 | 
				
			||||||
                basetemp = Path(self.given_basetemp)
 | 
					                basetemp = Path(self.given_basetemp)
 | 
				
			||||||
                ensure_reset_dir(basetemp)
 | 
					                ensure_reset_dir(basetemp)
 | 
				
			||||||
            else:
 | 
					            else:
 | 
				
			||||||
                temproot = Path(tempfile.gettempdir())
 | 
					                from_env = os.environ.get("PYTEST_DEBUG_TEMPROOT")
 | 
				
			||||||
 | 
					                temproot = Path(from_env or tempfile.gettempdir())
 | 
				
			||||||
                user = get_user() or "unknown"
 | 
					                user = get_user() or "unknown"
 | 
				
			||||||
                # use a sub-directory in the temproot to speed-up
 | 
					                # use a sub-directory in the temproot to speed-up
 | 
				
			||||||
                # make_numbered_dir() call
 | 
					                # make_numbered_dir() call
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -143,7 +143,6 @@ def break_getuser(monkeypatch):
 | 
				
			||||||
        monkeypatch.delenv(envvar, raising=False)
 | 
					        monkeypatch.delenv(envvar, raising=False)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@pytest.mark.skip(reason="creates random tmpdirs as part of a system level test")
 | 
					 | 
				
			||||||
@pytest.mark.usefixtures("break_getuser")
 | 
					@pytest.mark.usefixtures("break_getuser")
 | 
				
			||||||
@pytest.mark.skipif(sys.platform.startswith("win"), reason="no os.getuid on windows")
 | 
					@pytest.mark.skipif(sys.platform.startswith("win"), reason="no os.getuid on windows")
 | 
				
			||||||
def test_tmpdir_fallback_uid_not_found(testdir):
 | 
					def test_tmpdir_fallback_uid_not_found(testdir):
 | 
				
			||||||
| 
						 | 
					@ -162,7 +161,6 @@ def test_tmpdir_fallback_uid_not_found(testdir):
 | 
				
			||||||
    reprec.assertoutcome(passed=1)
 | 
					    reprec.assertoutcome(passed=1)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@pytest.mark.skip(reason="creates random tmpdirs as part of a system level test")
 | 
					 | 
				
			||||||
@pytest.mark.usefixtures("break_getuser")
 | 
					@pytest.mark.usefixtures("break_getuser")
 | 
				
			||||||
@pytest.mark.skipif(sys.platform.startswith("win"), reason="no os.getuid on windows")
 | 
					@pytest.mark.skipif(sys.platform.startswith("win"), reason="no os.getuid on windows")
 | 
				
			||||||
def test_get_user_uid_not_found():
 | 
					def test_get_user_uid_not_found():
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue