Attempting to patch terminal only if terminalreporter is available
This fixes the flag "--paste=all" when running tests with xdist, as slaves would attempt to patch a non-existing terminal during pytest_configure. Only the master node has a terminalreporter installed. --HG-- branch : pastebin-xdist
This commit is contained in:
		
							parent
							
								
									8859936301
								
							
						
					
					
						commit
						7e15fb7f2d
					
				|  | @ -14,8 +14,12 @@ def pytest_addoption(parser): | ||||||
| @pytest.mark.trylast | @pytest.mark.trylast | ||||||
| def pytest_configure(config): | def pytest_configure(config): | ||||||
|     if config.option.pastebin == "all": |     if config.option.pastebin == "all": | ||||||
|         config._pastebinfile = tempfile.TemporaryFile('w+') |  | ||||||
|         tr = config.pluginmanager.getplugin('terminalreporter') |         tr = config.pluginmanager.getplugin('terminalreporter') | ||||||
|  |         # if no terminal reporter plugin is present, nothing we can do here; | ||||||
|  |         # this can happen when this function executes in a slave node | ||||||
|  |         # when using pytest-xdist, for example | ||||||
|  |         if tr is not None: | ||||||
|  |             config._pastebinfile = tempfile.TemporaryFile('w+') | ||||||
|             oldwrite = tr._tw.write |             oldwrite = tr._tw.write | ||||||
|             def tee_write(s, **kwargs): |             def tee_write(s, **kwargs): | ||||||
|                 oldwrite(s, **kwargs) |                 oldwrite(s, **kwargs) | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue