Skip to content

Commit 7114a1b

Browse files
committed
Merge branch 'deprecate_pytest_namespace' into qt5reactor
2 parents 51c383d + d3b8579 commit 7114a1b

File tree

5 files changed

+24
-12
lines changed

5 files changed

+24
-12
lines changed

.travis.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ language: python
22
python:
33
- "2.7"
44
- "2.6"
5+
- "3.4"
6+
- "3.5"
7+
- "3.6"
58

69
install:
710
- pip install tox

README.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,22 +34,22 @@ inlineCallbacks
3434
=================
3535
Using `twisted.internet.defer.inlineCallbacks` as a decorator for test
3636
functions, which take funcargs, does not work. Please use
37-
`pytest.inlineCallbacks` instead::
37+
`pytest_twisted.inlineCallbacks` instead::
3838

39-
@pytest.inlineCallbacks
39+
@pytest_twisted.inlineCallbacks
4040
def test_some_stuff(tmpdir):
4141
res = yield threads.deferToThread(os.listdir, tmpdir.strpath)
4242
assert res == []
4343

4444
Waiting for deferreds in fixtures
4545
=================================
46-
`pytest.blockon` allows fixtures to wait for deferreds::
46+
`pytest_twisted.blockon` allows fixtures to wait for deferreds::
4747

4848
@pytest.fixture
4949
def val():
5050
d = defer.Deferred()
5151
reactor.callLater(1.0, d.callback, 10)
52-
return pytest.blockon(d)
52+
return pytest_twisted.blockon(d)
5353

5454

5555
The twisted greenlet

pytest_twisted.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,13 @@
1212

1313

1414
def blockon(d):
15+
if reactor.running:
16+
return block_from_thread(d)
17+
18+
return blockon_default(d)
19+
20+
21+
def blockon_default(d):
1522
current = greenlet.getcurrent()
1623
assert current is not gr_twisted, \
1724
"blockon cannot be called from the twisted greenlet"
@@ -45,7 +52,7 @@ def inlineCallbacks(fun, *args, **kw):
4552

4653
def pytest_namespace():
4754
return dict(inlineCallbacks=inlineCallbacks,
48-
blockon=block_from_thread if reactor.running else blockon)
55+
blockon=blockon)
4956

5057

5158
def stop_twisted_greenlet():
@@ -148,7 +155,7 @@ def in_reactor(d, f, *args):
148155

149156
d = defer.Deferred()
150157
reactor.callLater(0.0, in_reactor, d, _pytest_pyfunc_call, pyfuncitem)
151-
blockon(d)
158+
blockon_default(d)
152159
else:
153160
if not reactor.running:
154161
raise RuntimeError("twisted reactor is not running")

testing/test_basic.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -63,14 +63,15 @@ def test_inlineCallbacks(testdir):
6363
testdir.makepyfile("""
6464
from twisted.internet import reactor, defer
6565
import pytest
66+
import pytest_twisted
6667
6768
@pytest.fixture(scope="module",
6869
params=["fs", "imap", "web"])
6970
def foo(request):
7071
return request.param
7172
7273
73-
@pytest.inlineCallbacks
74+
@pytest_twisted.inlineCallbacks
7475
def test_succeed(foo):
7576
yield defer.succeed(foo)
7677
if foo == "web":
@@ -107,13 +108,13 @@ def test_MAIN():
107108

108109
def test_blocon_in_hook(testdir):
109110
testdir.makeconftest("""
110-
import pytest
111+
import pytest_twisted as pt
111112
from twisted.internet import reactor, defer
112113
113114
def pytest_configure(config):
114115
d = defer.Deferred()
115116
reactor.callLater(0.01, d.callback, 1)
116-
pytest.blockon(d)
117+
pt.blockon(d)
117118
""")
118119
testdir.makepyfile("""
119120
from twisted.internet import reactor, defer
@@ -131,18 +132,19 @@ def test_succeed():
131132
def test_pytest_from_reactor_thread(testdir):
132133
testdir.makepyfile("""
133134
import pytest
135+
import pytest_twisted
134136
from twisted.internet import reactor, defer
135137
136138
@pytest.fixture
137139
def fix():
138140
d = defer.Deferred()
139141
reactor.callLater(0.01, d.callback, 42)
140-
return pytest.blockon(d)
142+
return pytest_twisted.blockon(d)
141143
142144
def test_simple(fix):
143145
assert fix == 42
144146
145-
@pytest.inlineCallbacks
147+
@pytest_twisted.inlineCallbacks
146148
def test_fail():
147149
d = defer.Deferred()
148150
reactor.callLater(0.01, d.callback, 1)

tox.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[tox]
2-
envlist = py26,py27,linting
2+
envlist = py{26,27,34,35,36},linting
33

44

55
[testenv]

0 commit comments

Comments
 (0)