Skip to content

Commit 4a11c51

Browse files
committed
Fix some broken tests in CI
1 parent 7b75668 commit 4a11c51

File tree

8 files changed

+59
-98
lines changed

8 files changed

+59
-98
lines changed

.github/workflows/ci.yml

+4-4
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@ on:
99
jobs:
1010
Windows:
1111
name: 'Windows (${{ matrix.python }}, ${{ matrix.arch }}${{ matrix.extra_name }})'
12-
timeout-minutes: 20
12+
timeout-minutes: 30
1313
runs-on: 'windows-latest'
1414
strategy:
1515
fail-fast: false
1616
matrix:
17-
python: ['3.7', '3.8', '3.9', '3.10', '3.11', 'pypy-3.8-nightly', 'pypy-3.9-nightly']
17+
python: ['3.7', '3.8', '3.9', '3.10', '3.11']
1818
arch: ['x86', 'x64']
1919
exclude:
2020
- python: 'pypy-3.8-nightly'
@@ -51,7 +51,7 @@ jobs:
5151

5252
Ubuntu:
5353
name: 'Ubuntu (${{ matrix.python }}${{ matrix.extra_name }})'
54-
timeout-minutes: 10
54+
timeout-minutes: 20
5555
runs-on: 'ubuntu-latest'
5656
strategy:
5757
fail-fast: false
@@ -98,7 +98,7 @@ jobs:
9898

9999
macOS:
100100
name: 'macOS (${{ matrix.python }})'
101-
timeout-minutes: 10
101+
timeout-minutes: 20
102102
runs-on: 'macos-latest'
103103
strategy:
104104
fail-fast: false

ci.sh

+8-11
Original file line numberDiff line numberDiff line change
@@ -71,21 +71,18 @@ else
7171
mkdir empty || true
7272
cd empty
7373

74-
INSTALLDIR=$(python -c "import os, trio_asyncio; print(os.path.dirname(trio_asyncio.__file__))")
75-
cp ../pyproject.toml $INSTALLDIR
76-
77-
# support subprocess spawning with coverage.py
78-
echo "import coverage; coverage.process_startup()" | tee -a "$INSTALLDIR/../sitecustomize.py"
79-
80-
if COVERAGE_PROCESS_START=$(pwd)/../.coveragerc coverage run --rcfile=../.coveragerc -m pytest -r a --junitxml=../test-results.xml --verbose ../tests; then
74+
cp ../pyproject.toml ../tests/
75+
76+
# We have to copy .coveragerc into this directory, rather than passing
77+
# --cov-config=../.coveragerc to pytest, because codecov.sh will run
78+
# 'coverage xml' to generate the report that it uses, and that will only
79+
# apply the ignore patterns in the current directory's .coveragerc.
80+
cp ../.coveragerc .
81+
if pytest -ra --junitxml=../test-results.xml --cov=trio_asyncio --verbose ../tests; then
8182
PASSED=true
8283
else
8384
PASSED=false
8485
fi
8586

86-
coverage combine --rcfile ../.coveragerc
87-
coverage report -m --rcfile ../.coveragerc
88-
coverage xml --rcfile ../.coveragerc
89-
9087
$PASSED
9188
fi

pyproject.toml

+17
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,20 @@
1+
[tool.pytest.ini_options]
2+
addopts = ["-p", "no:asyncio"]
3+
filterwarnings = [
4+
"error",
5+
"ignore:The loop argument is deprecated since Python 3.8:DeprecationWarning",
6+
'ignore:"@coroutine" decorator is deprecated since Python 3.8:DeprecationWarning',
7+
"default:Tried to add marker .* but that test doesn't exist.:RuntimeWarning",
8+
"ignore:the imp module is deprecated in favour of importlib.*:DeprecationWarning",
9+
"ignore:'AbstractChildWatcher' is deprecated.*:DeprecationWarning"
10+
]
11+
junit_family = "xunit2"
12+
xfail_strict = true
13+
14+
[tool.flake8]
15+
max-line-length = 99
16+
extend-ignore = ['D', 'E402', 'E731', 'E127', 'E502', 'E123', 'W503']
17+
118
[tool.towncrier]
219
package = "trio_asyncio"
320
title_format = "trio-asyncio {version} ({project_date})"

setup.cfg

-10
This file was deleted.

tests/pytest.ini

-6
This file was deleted.

tests/python/conftest.py

+22-60
Original file line numberDiff line numberDiff line change
@@ -124,71 +124,37 @@ def skip(rel_id):
124124
"test_tasks.py::RunCoroutineThreadsafeTests::"
125125
"test_run_coroutine_threadsafe_task_cancelled"
126126
)
127-
xfail(
128-
"test_tasks.py::RunCoroutineThreadsafeTests::"
129-
"test_run_coroutine_threadsafe_with_timeout"
130-
)
127+
if sys.version_info < (3, 11):
128+
xfail(
129+
"test_tasks.py::RunCoroutineThreadsafeTests::"
130+
"test_run_coroutine_threadsafe_with_timeout"
131+
)
131132
if sys.platform == "win32":
132133
xfail("test_windows_events.py::ProactorLoopCtrlC::test_ctrl_c")
133134

134-
# The CPython SSL tests ignored here fail with
135-
# ConnectionResetError on Pythons <= 3.7.x for some unknown x.
136-
# (3.7.1 fails, 3.7.5 and 3.7.6 pass; older 3.6.x also affected)
137-
if sys.platform != "win32":
138-
import selectors
139-
140-
xfail_per_eventloop = []
141-
if sys.implementation.name == "pypy":
142-
# pypy uses a different spelling of the certificate
143-
# failure error message which causes this test to spuriously fail
144-
xfail_per_eventloop += [
145-
"test_create_server_ssl_match_failed"
146-
]
147-
else:
148-
if sys.version_info < (3, 8):
149-
xfail_per_eventloop += [
150-
"test_create_ssl_connection",
151-
"test_create_ssl_unix_connection"
152-
]
153-
154-
kinds = ("Select",)
155-
for candidate in ("Kqueue", "Epoll", "Poll"):
156-
if hasattr(selectors, candidate + "Selector"):
157-
kinds += (candidate.replace("Epoll", "EPoll"),)
158-
for kind in kinds:
159-
for test in xfail_per_eventloop:
160-
xfail("test_events.py::{}EventLoopTests::{}".format(kind, test))
161-
162-
if sys.implementation.name != "pypy":
163-
stream_suite = "StreamTests"
164-
for which in ("open_connection", "open_unix_connection"):
165-
xfail(
166-
"test_streams.py::{}::test_{}_no_loop_ssl"
167-
.format(stream_suite, which)
168-
)
169-
170135
if sys.implementation.name == "pypy":
171-
# This fails due to a trivial difference in how pypy handles IPv6
172-
# addresses
173-
xfail(
174-
"test_base_events.py::BaseEventLoopWithSelectorTests::"
175-
"test_create_connection_ipv6_scope"
176-
)
177136
# This test depends on the C implementation of asyncio.Future, and
178137
# unlike most such tests it is not configured to be skipped if
179138
# the C implementation is not available
180139
xfail(
181140
"test_futures.py::CFutureInheritanceTests::"
182141
"test_inherit_without_calling_super_init"
183142
)
184-
# These tests assume CPython-style immediate finalization of
185-
# objects when they become unreferenced
186-
for test in (
187-
"test_create_connection_memory_leak",
188-
"test_handshake_timeout",
189-
"test_start_tls_client_reg_proto_1",
190-
):
191-
xfail("test_sslproto.py::SelectorStartTLSTests::{}".format(test))
143+
if sys.version_info < (3, 8):
144+
# This fails due to a trivial difference in how pypy handles IPv6
145+
# addresses
146+
xfail(
147+
"test_base_events.py::BaseEventLoopWithSelectorTests::"
148+
"test_create_connection_ipv6_scope"
149+
)
150+
# These tests assume CPython-style immediate finalization of
151+
# objects when they become unreferenced
152+
for test in (
153+
"test_create_connection_memory_leak",
154+
"test_handshake_timeout",
155+
"test_start_tls_client_reg_proto_1",
156+
):
157+
xfail("test_sslproto.py::SelectorStartTLSTests::{}".format(test))
192158

193159
if sys.version_info >= (3, 11):
194160
# This tries to use a mock ChildWatcher that does something unlikely.
@@ -198,12 +164,8 @@ def skip(rel_id):
198164
"test_subprocess.py::GenericWatcherTests::"
199165
"test_create_subprocess_fails_with_inactive_watcher"
200166
)
167+
168+
if sys.version_info >= (3, 9):
201169
# This tries to create a new loop from within an existing one,
202170
# which we don't support.
203171
xfail("test_locks.py::ConditionTests::test_ambiguous_loops")
204-
# This asserts that a deprecation warning refers to the point of
205-
# the call, but our monkeypatching interposes another stack frame
206-
xfail(
207-
"test_events.py::TestCGetEventLoop::"
208-
"test_get_event_loop_returns_running_loop2"
209-
)

trio_asyncio/_base.py

+7-3
Original file line numberDiff line numberDiff line change
@@ -209,9 +209,13 @@ async def run_aio_coroutine(self, coro):
209209
This is a Trio-flavored async function.
210210
211211
"""
212-
self._check_closed()
213-
t = sniffio.current_async_library_cvar.set("asyncio")
214-
fut = asyncio.ensure_future(coro, loop=self)
212+
try:
213+
self._check_closed()
214+
t = sniffio.current_async_library_cvar.set("asyncio")
215+
fut = asyncio.ensure_future(coro, loop=self)
216+
except BaseException:
217+
coro.close() # avoid unawaited coroutine error
218+
raise
215219
try:
216220
return await run_aio_future(fut)
217221
finally:

trio_asyncio/_loop.py

+1-4
Original file line numberDiff line numberDiff line change
@@ -201,10 +201,7 @@ def _new_policy_set(new_policy):
201201
raise RuntimeError("You can't set the Trio loop policy manually")
202202
if _in_trio_context():
203203
raise RuntimeError("You can't change the event loop policy in Trio context")
204-
if (
205-
new_policy is not None
206-
and not isinstance(new_policy, asyncio.AbstractEventLoopPolicy)
207-
):
204+
if (new_policy is not None and not isinstance(new_policy, asyncio.AbstractEventLoopPolicy)):
208205
# Raise the type of error that the CPython test suite expects
209206
raise_type = TypeError if sys.version_info >= (3, 11) else AssertionError
210207
raise raise_type(

0 commit comments

Comments
 (0)