Skip to content

Commit 1619b12

Browse files
committed
test(pytest_plugin): I have no idea *why* this works
The request context isn't detected inside the doctest unless I run locals(). The request context is needed to join the example code's import so the type annotation shows.
1 parent 908459d commit 1619b12

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

src/libtmux/pytest_plugin.py

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -112,19 +112,28 @@ def server(
112112
113113
>>> from libtmux.server import Server
114114
115-
>>> def test_example(server: "Server"):
115+
>>> def test_example(server: Server):
116+
... assert isinstance(server, Server)
116117
... session = server.new_session('my session')
117118
... assert len(server.sessions) == 1
118119
... assert [session.name.startswith('my') for session in server.sessions]
119120
120121
.. ::
121122
122-
>>> import inspect
123-
>>> test_mod = pytester.makepyfile(whatever=inspect.getsource(test_example))
124-
>>> result = pytester.inline_run(str(test_mod), '--disable-warnings')
123+
>>> locals().keys()
124+
dict_keys(...)
125+
126+
>>> source = ''.join([
127+
... example.source for example in request._pyfuncitem.dtest.examples
128+
... ][:3])
129+
130+
>>> pytester.makepyfile(**{'whatever.py': source})
131+
PosixPath(...)
132+
133+
>>> result = pytester.runpytest('whatever.py', '--disable-warnings')
125134
===...
126135
127-
>>> result.assertoutcome(passed=1)
136+
>>> result.assert_outcomes(passed=1)
128137
"""
129138
t = Server()
130139
t.socket_name = "libtmux_test%s" % next(namer)

0 commit comments

Comments
 (0)