From 7e15fb7f2d0130bfdee240a654f3d88119fbb73b Mon Sep 17 00:00:00 2001 From: Bruno Oliveira Date: Mon, 19 Jan 2015 19:20:01 -0200 Subject: [PATCH] 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 --- _pytest/pastebin.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/_pytest/pastebin.py b/_pytest/pastebin.py index be4b464f8..4d0badbf2 100644 --- a/_pytest/pastebin.py +++ b/_pytest/pastebin.py @@ -14,13 +14,17 @@ def pytest_addoption(parser): @pytest.mark.trylast def pytest_configure(config): if config.option.pastebin == "all": - config._pastebinfile = tempfile.TemporaryFile('w+') tr = config.pluginmanager.getplugin('terminalreporter') - oldwrite = tr._tw.write - def tee_write(s, **kwargs): - oldwrite(s, **kwargs) - config._pastebinfile.write(str(s)) - tr._tw.write = tee_write + # 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 + def tee_write(s, **kwargs): + oldwrite(s, **kwargs) + config._pastebinfile.write(str(s)) + tr._tw.write = tee_write def pytest_unconfigure(config): if hasattr(config, '_pastebinfile'):