summaryrefslogtreecommitdiff
path: root/tests/mixins.py
diff options
context:
space:
mode:
authorNed Batchelder <ned@nedbatchelder.com>2021-02-02 09:12:47 -0500
committerNed Batchelder <ned@nedbatchelder.com>2021-02-02 09:12:47 -0500
commit80c021d9174e7ae3e5183f1902903fb90a891246 (patch)
treea0edae6ca0996217b9f0fa3213f824eab8b1cbe1 /tests/mixins.py
parent9012623110f49635fff61d19a4f5bb779de91b99 (diff)
downloadpython-coveragepy-git-80c021d9174e7ae3e5183f1902903fb90a891246.tar.gz
refactor: remove reliance on unittest_mixins.StdStreamCapturingMixin
This is another step toward removing unittest.TestCase as a base class.
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