summaryrefslogtreecommitdiff
path: root/tests/mixins.py
diff options
context:
space:
mode:
Diffstat (limited to 'tests/mixins.py')
-rw-r--r--tests/mixins.py31
1 files changed, 31 insertions, 0 deletions
diff --git a/tests/mixins.py b/tests/mixins.py
index 97ca093c..ab0623c0 100644
--- a/tests/mixins.py
+++ b/tests/mixins.py
@@ -10,6 +10,8 @@ Some of these are transitional while working toward pure-pytest style.
import functools
import types
+import pytest
+
from coverage.backunittest import unittest
from coverage.misc import StopEverything
@@ -37,3 +39,32 @@ class SkipConvertingMetaclass(type):
StopEverythingMixin = SkipConvertingMetaclass('StopEverythingMixin', (), {})
+
+
+class StdStreamCapturingMixin:
+ """
+ Adapter from the pytest capsys fixture to more convenient methods.
+
+ This doesn't also output to the real stdout, so we probably want to move
+ to "real" capsys when we can use fixtures in test methods.
+
+ Once you've used one of these methods, the capturing is reset, so another
+ invocation will only return the delta.
+
+ """
+ @pytest.fixture(autouse=True)
+ def _capcapsys(self, capsys):
+ """Grab the fixture so our methods can use it."""
+ self.capsys = capsys
+
+ def stdouterr(self):
+ """Returns (out, err), two strings for stdout and stderr."""
+ return self.capsys.readouterr()
+
+ def stdout(self):
+ """Returns a string, the captured stdout."""
+ return self.capsys.readouterr().out
+
+ def stderr(self):
+ """Returns a string, the captured stderr."""
+ return self.capsys.readouterr().err