Skip to content

Commit

Permalink
WIP support pytest 8.x.
Browse files Browse the repository at this point in the history
  • Loading branch information
icemac committed May 8, 2024
1 parent a380203 commit e4e0049
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 5 deletions.
31 changes: 30 additions & 1 deletion src/zope/pytestlayer/doctest.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,28 @@ def tearDown(self):
NOOP_LAYER = NoOpLayer()


class PatchedDocTestSuite:

def __init__(self, suite):
self._suite = suite

def __call__(self, *args, **kw):
result = None
if args:
if not isinstance(args[0], str):
result = args[0]
return self.run(result)

def __getattr__(self, name):
return getattr(self._suite, name)

def __setattr__(self, name, value):
if name == '_suite':
self.__dict__[name] = value
else:
setattr(self._suite, name, value)


def DocTestSuite(*args, **kw):
"""A DocTestSuite whose tests are detectable by zope.pytestlayer.
Expand All @@ -28,4 +50,11 @@ def DocTestSuite(*args, **kw):
layer = kw.pop('layer', NOOP_LAYER)
suite = doctest.DocTestSuite(*args, **kw)
suite.layer = layer
return suite
return PatchedDocTestSuite(suite)


def layered(suite, layer=NOOP_LAYER):
"""XXX
"""
suite.layer = layer
return PatchedDocTestSuite(suite)
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import doctest
import unittest

from plone.testing import layered

from zope.pytestlayer.doctest import layered
from zope.pytestlayer.testing import log_to_terminal


Expand Down
4 changes: 2 additions & 2 deletions src/zope/pytestlayer/tests/test_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ def test_single_layer_in_two_modules(where):

def test_single_layered_suite(where):
lines = run_pytest('single_layered_suite')
assert """\
assert join(lines) == """\
plugins: zope.pytestlayer
collecting ... collected 1 item
src/zope/pytestlayer/tests/fixture/single_layered_suite/test_core.py <- test_suite: /src/zope/pytestlayer/tests/fixture/single_layered_suite/doctest.txt single_layered_suite.test_core.FooLayer
Expand All @@ -156,7 +156,7 @@ def test_single_layered_suite(where):
src/zope/pytestlayer/tests/fixture/single_layered_suite/test_core.py <- test_suite: /src/zope/pytestlayer/tests/fixture/single_layered_suite/doctest.txt PASSED
testTearDown foo
Tear down single_layered_suite.test_core.FooLayer in N.NNN seconds.
""" == join(lines)
"""
assert '=== 1 passed' in lines[-1]


Expand Down

0 comments on commit e4e0049

Please sign in to comment.