make sessionfinish hooks execute with the same cwd-context as at
session start (helps fix plugin behaviour which write output files with relative path such as pytest-cov)
This commit is contained in:
		
							parent
							
								
									2951c3ace9
								
							
						
					
					
						commit
						ac3d8800fd
					
				|  | @ -1,6 +1,10 @@ | ||||||
| Changes between 2.3.5 and 2.4.DEV | Changes between 2.3.5 and 2.4.DEV | ||||||
| ----------------------------------- | ----------------------------------- | ||||||
| 
 | 
 | ||||||
|  | - make sessionfinish hooks execute with the same cwd-context as at | ||||||
|  |   session start (helps fix plugin behaviour which write output files  | ||||||
|  |   with relative path such as pytest-cov) | ||||||
|  | 
 | ||||||
| - fix issue316 - properly reference collection hooks in docs | - fix issue316 - properly reference collection hooks in docs | ||||||
| 
 | 
 | ||||||
| - fix issue 308 - allow to mark/xfail/skip individual parameter sets | - fix issue 308 - allow to mark/xfail/skip individual parameter sets | ||||||
|  |  | ||||||
|  | @ -97,6 +97,7 @@ def wrap_session(config, doit): | ||||||
|             if session._testsfailed: |             if session._testsfailed: | ||||||
|                 session.exitstatus = EXIT_TESTSFAILED |                 session.exitstatus = EXIT_TESTSFAILED | ||||||
|     finally: |     finally: | ||||||
|  |         session.startdir.chdir() | ||||||
|         if initstate >= 2: |         if initstate >= 2: | ||||||
|             config.hook.pytest_sessionfinish( |             config.hook.pytest_sessionfinish( | ||||||
|                 session=session, |                 session=session, | ||||||
|  | @ -452,6 +453,7 @@ class Session(FSCollector): | ||||||
|         self.shouldstop = False |         self.shouldstop = False | ||||||
|         self.trace = config.trace.root.get("collection") |         self.trace = config.trace.root.get("collection") | ||||||
|         self._norecursepatterns = config.getini("norecursedirs") |         self._norecursepatterns = config.getini("norecursedirs") | ||||||
|  |         self.startdir = py.path.local() | ||||||
| 
 | 
 | ||||||
|     def pytest_collectstart(self): |     def pytest_collectstart(self): | ||||||
|         if self.shouldstop: |         if self.shouldstop: | ||||||
|  |  | ||||||
|  | @ -226,3 +226,17 @@ def test_exclude(testdir): | ||||||
|     assert result.ret == 0 |     assert result.ret == 0 | ||||||
|     result.stdout.fnmatch_lines(["*1 passed*"]) |     result.stdout.fnmatch_lines(["*1 passed*"]) | ||||||
| 
 | 
 | ||||||
|  | def test_sessionfinish_with_start(testdir): | ||||||
|  |     testdir.makeconftest(""" | ||||||
|  |         import os | ||||||
|  |         l = [] | ||||||
|  |         def pytest_sessionstart(): | ||||||
|  |             l.append(os.getcwd()) | ||||||
|  |             os.chdir("..") | ||||||
|  | 
 | ||||||
|  |         def pytest_sessionfinish(): | ||||||
|  |             assert l[0] == os.getcwd() | ||||||
|  | 
 | ||||||
|  |     """) | ||||||
|  |     res = testdir.runpytest("--collectonly") | ||||||
|  |     assert res.ret == 0 | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue