diff --git a/testing/conftest.py b/testing/conftest.py new file mode 100644 index 00000000..ae3674e3 --- /dev/null +++ b/testing/conftest.py @@ -0,0 +1,23 @@ +import os +import sys +import pytest + address@hidden(scope=u"function") +def redirect_stdin(): + u"""GPG requires stdin to be open and have real file descriptor, which interferes with pytest's capture facility. + Work around this by redirecting /dev/null to stdin temporarily. + + Activate this fixture on unittest test methods and classes by means of @pytest.mark.usefixtures("redirect_stdin").""" + try: + targetfd_save = os.dup(0) + stdin_save = sys.stdin + + nullfile = open(os.devnull, u"r") + sys.stdin = nullfile + os.dup2(nullfile.fileno(), 0) + yield + finally: + os.dup2(targetfd_save, 0) + sys.stdin = stdin_save + os.close(targetfd_save) + nullfile.close() \ No newline at end of file diff --git a/testing/unit/test_collections.py b/testing/unit/test_collections.py index a466c738..ba57b755 100644 --- a/testing/unit/test_collections.py +++ b/testing/unit/test_collections.py @@ -183,7 +183,7 @@ class CollectionTest(UnitTestCase): test_fileobj(1, u"hello 1") test_fileobj(2, u"Hello 2") - @pytest.mark.nocapture + @pytest.mark.usefixtures(u"redirect_stdin") def test_sigchain_fileobj(self): u"""Test getting signature chain fileobjs from archive_dir_path""" self.set_gpg_profile() diff --git a/testing/unit/test_gpg.py b/testing/unit/test_gpg.py index 4b1fedc2..c032433f 100644 --- a/testing/unit/test_gpg.py +++ b/testing/unit/test_gpg.py @@ -30,7 +30,7 @@ from duplicity import path from . import UnitTestCase address@hidden address@hidden(u"redirect_stdin") class GPGTest(UnitTestCase): u"""Test GPGFile""" def setUp(self): diff --git a/tox.ini b/tox.ini index 1bc83bf5..23b0afbf 100644 --- a/tox.ini +++ b/tox.ini @@ -5,10 +5,7 @@ setenv = RUN_CODE_TESTS=0 [testenv:py27] deps = -rrequirements.txt -commands = - pytest -m "not nocapture" {posargs} - pytest -s -m "nocapture" {posargs} - +commands = pytest {posargs} [testenv:code] setenv = RUN_CODE_TESTS=1