From dc37b792eda68cd6ee1240fe2984290adb8e9eca Mon Sep 17 00:00:00 2001
From: jakkdl
Date: Wed, 5 Apr 2023 15:22:05 +0200
Subject: [PATCH 1/4] move **/tests/ to **/_tests/
---
.coveragerc | 2 +-
MANIFEST.in | 2 +-
ci.sh | 4 +--
trio/_core/{tests => _tests}/__init__.py | 0
trio/_core/{tests => _tests}/test_asyncgen.py | 0
.../{tests => _tests}/test_guest_mode.py | 0
.../{tests => _tests}/test_instrumentation.py | 0
trio/_core/{tests => _tests}/test_io.py | 0
trio/_core/{tests => _tests}/test_ki.py | 0
trio/_core/{tests => _tests}/test_local.py | 0
.../{tests => _tests}/test_mock_clock.py | 0
.../{tests => _tests}/test_multierror.py | 0
.../test_multierror_scripts/__init__.py | 0
.../test_multierror_scripts/_common.py | 0
.../apport_excepthook.py | 0
.../ipython_custom_exc.py | 0
.../simple_excepthook.py | 0
.../simple_excepthook_IPython.py | 0
.../{tests => _tests}/test_parking_lot.py | 0
trio/_core/{tests => _tests}/test_run.py | 0
.../{tests => _tests}/test_thread_cache.py | 0
trio/_core/{tests => _tests}/test_tutil.py | 0
.../{tests => _tests}/test_unbounded_queue.py | 0
trio/_core/{tests => _tests}/test_util.py | 0
trio/_core/{tests => _tests}/test_windows.py | 0
trio/_core/{tests => _tests}/tutil.py | 4 +--
trio/_core/tests/conftest.py | 25 ------------------
trio/{tests => _tests}/__init__.py | 0
.../astrill-codesigning-cert.cer | Bin
.../module_with_deprecations.py | 0
.../conftest.py => _tests/pytest_plugin.py} | 2 +-
trio/{tests => _tests}/test_abc.py | 0
trio/{tests => _tests}/test_channel.py | 0
trio/{tests => _tests}/test_contextvars.py | 0
trio/{tests => _tests}/test_deprecate.py | 0
trio/{tests => _tests}/test_dtls.py | 2 +-
trio/{tests => _tests}/test_exports.py | 11 +-------
trio/{tests => _tests}/test_fakenet.py | 0
trio/{tests => _tests}/test_file_io.py | 0
.../test_highlevel_generic.py | 0
.../test_highlevel_open_tcp_listeners.py | 2 +-
.../test_highlevel_open_tcp_stream.py | 0
.../test_highlevel_open_unix_stream.py | 0
.../test_highlevel_serve_listeners.py | 0
.../test_highlevel_socket.py | 0
.../test_highlevel_ssl_helpers.py | 0
trio/{tests => _tests}/test_path.py | 0
.../test_scheduler_determinism.py | 0
trio/{tests => _tests}/test_signals.py | 0
trio/{tests => _tests}/test_socket.py | 2 +-
trio/{tests => _tests}/test_ssl.py | 2 +-
trio/{tests => _tests}/test_subprocess.py | 2 +-
trio/{tests => _tests}/test_sync.py | 0
trio/{tests => _tests}/test_testing.py | 2 +-
trio/{tests => _tests}/test_threads.py | 8 +++---
trio/{tests => _tests}/test_timeouts.py | 2 +-
trio/{tests => _tests}/test_tracing.py | 0
trio/{tests => _tests}/test_unix_pipes.py | 2 +-
trio/{tests => _tests}/test_util.py | 2 +-
.../{tests => _tests}/test_wait_for_object.py | 2 +-
trio/{tests => _tests}/test_windows_pipes.py | 2 +-
trio/{tests => _tests}/tools/__init__.py | 0
.../tools/test_gen_exports.py | 0
trio/tests.py | 10 +++++++
64 files changed, 33 insertions(+), 57 deletions(-)
rename trio/_core/{tests => _tests}/__init__.py (100%)
rename trio/_core/{tests => _tests}/test_asyncgen.py (100%)
rename trio/_core/{tests => _tests}/test_guest_mode.py (100%)
rename trio/_core/{tests => _tests}/test_instrumentation.py (100%)
rename trio/_core/{tests => _tests}/test_io.py (100%)
rename trio/_core/{tests => _tests}/test_ki.py (100%)
rename trio/_core/{tests => _tests}/test_local.py (100%)
rename trio/_core/{tests => _tests}/test_mock_clock.py (100%)
rename trio/_core/{tests => _tests}/test_multierror.py (100%)
rename trio/_core/{tests => _tests}/test_multierror_scripts/__init__.py (100%)
rename trio/_core/{tests => _tests}/test_multierror_scripts/_common.py (100%)
rename trio/_core/{tests => _tests}/test_multierror_scripts/apport_excepthook.py (100%)
rename trio/_core/{tests => _tests}/test_multierror_scripts/ipython_custom_exc.py (100%)
rename trio/_core/{tests => _tests}/test_multierror_scripts/simple_excepthook.py (100%)
rename trio/_core/{tests => _tests}/test_multierror_scripts/simple_excepthook_IPython.py (100%)
rename trio/_core/{tests => _tests}/test_parking_lot.py (100%)
rename trio/_core/{tests => _tests}/test_run.py (100%)
rename trio/_core/{tests => _tests}/test_thread_cache.py (100%)
rename trio/_core/{tests => _tests}/test_tutil.py (100%)
rename trio/_core/{tests => _tests}/test_unbounded_queue.py (100%)
rename trio/_core/{tests => _tests}/test_util.py (100%)
rename trio/_core/{tests => _tests}/test_windows.py (100%)
rename trio/_core/{tests => _tests}/tutil.py (97%)
delete mode 100644 trio/_core/tests/conftest.py
rename trio/{tests => _tests}/__init__.py (100%)
rename trio/{tests => _tests}/astrill-codesigning-cert.cer (100%)
rename trio/{tests => _tests}/module_with_deprecations.py (100%)
rename trio/{tests/conftest.py => _tests/pytest_plugin.py} (93%)
rename trio/{tests => _tests}/test_abc.py (100%)
rename trio/{tests => _tests}/test_channel.py (100%)
rename trio/{tests => _tests}/test_contextvars.py (100%)
rename trio/{tests => _tests}/test_deprecate.py (100%)
rename trio/{tests => _tests}/test_dtls.py (99%)
rename trio/{tests => _tests}/test_exports.py (97%)
rename trio/{tests => _tests}/test_fakenet.py (100%)
rename trio/{tests => _tests}/test_file_io.py (100%)
rename trio/{tests => _tests}/test_highlevel_generic.py (100%)
rename trio/{tests => _tests}/test_highlevel_open_tcp_listeners.py (99%)
rename trio/{tests => _tests}/test_highlevel_open_tcp_stream.py (100%)
rename trio/{tests => _tests}/test_highlevel_open_unix_stream.py (100%)
rename trio/{tests => _tests}/test_highlevel_serve_listeners.py (100%)
rename trio/{tests => _tests}/test_highlevel_socket.py (100%)
rename trio/{tests => _tests}/test_highlevel_ssl_helpers.py (100%)
rename trio/{tests => _tests}/test_path.py (100%)
rename trio/{tests => _tests}/test_scheduler_determinism.py (100%)
rename trio/{tests => _tests}/test_signals.py (100%)
rename trio/{tests => _tests}/test_socket.py (99%)
rename trio/{tests => _tests}/test_ssl.py (99%)
rename trio/{tests => _tests}/test_subprocess.py (99%)
rename trio/{tests => _tests}/test_sync.py (100%)
rename trio/{tests => _tests}/test_testing.py (99%)
rename trio/{tests => _tests}/test_threads.py (99%)
rename trio/{tests => _tests}/test_timeouts.py (98%)
rename trio/{tests => _tests}/test_tracing.py (100%)
rename trio/{tests => _tests}/test_unix_pipes.py (99%)
rename trio/{tests => _tests}/test_util.py (99%)
rename trio/{tests => _tests}/test_wait_for_object.py (99%)
rename trio/{tests => _tests}/test_windows_pipes.py (98%)
rename trio/{tests => _tests}/tools/__init__.py (100%)
rename trio/{tests => _tests}/tools/test_gen_exports.py (100%)
create mode 100644 trio/tests.py
diff --git a/.coveragerc b/.coveragerc
index 4bbac7b27d..83a7cf0647 100644
--- a/.coveragerc
+++ b/.coveragerc
@@ -6,7 +6,7 @@ source=trio
omit=
setup.py
*/ipython_custom_exc.py
-# Omit the generated files in trio/_core starting with _public_
+# Omit the generated files in trio/_core starting with _generated_
*/trio/_core/_generated_*
# The test suite spawns subprocesses to test some stuff, so make sure
# this doesn't corrupt the coverage files
diff --git a/MANIFEST.in b/MANIFEST.in
index e2fd4c157f..8b92523fb7 100644
--- a/MANIFEST.in
+++ b/MANIFEST.in
@@ -2,6 +2,6 @@ include LICENSE LICENSE.MIT LICENSE.APACHE2
include README.rst
include CODE_OF_CONDUCT.md CONTRIBUTING.md
include test-requirements.txt
-recursive-include trio/tests/test_ssl_certs *.pem
+recursive-include trio/_tests/test_ssl_certs *.pem
recursive-include docs *
prune docs/build
diff --git a/ci.sh b/ci.sh
index 2fc44c0b45..3cd78cfb18 100755
--- a/ci.sh
+++ b/ci.sh
@@ -81,7 +81,7 @@ else
# when installing, and then running 'certmgr.msc' and exporting the
# certificate. See:
# http://www.migee.com/2010/09/24/solution-for-unattendedsilent-installs-and-would-you-like-to-install-this-device-software/
- certutil -addstore "TrustedPublisher" trio/tests/astrill-codesigning-cert.cer
+ certutil -addstore "TrustedPublisher" trio/_tests/astrill-codesigning-cert.cer
# Double-slashes are how you tell windows-bash that you want a single
# slash, and don't treat this as a unix-style filename that needs to
# be replaced by a windows-style filename.
@@ -107,7 +107,7 @@ else
# 'coverage xml' to generate the report that it uses, and that will only
# apply the ignore patterns in the current directory's .coveragerc.
cp ../.coveragerc .
- if pytest -r a --junitxml=../test-results.xml --run-slow ${INSTALLDIR} --cov="$INSTALLDIR" --verbose; then
+ if pytest -r a -p trio._tests.pytest_plugin --junitxml=../test-results.xml --run-slow ${INSTALLDIR} --cov="$INSTALLDIR" --verbose; then
PASSED=true
else
PASSED=false
diff --git a/trio/_core/tests/__init__.py b/trio/_core/_tests/__init__.py
similarity index 100%
rename from trio/_core/tests/__init__.py
rename to trio/_core/_tests/__init__.py
diff --git a/trio/_core/tests/test_asyncgen.py b/trio/_core/_tests/test_asyncgen.py
similarity index 100%
rename from trio/_core/tests/test_asyncgen.py
rename to trio/_core/_tests/test_asyncgen.py
diff --git a/trio/_core/tests/test_guest_mode.py b/trio/_core/_tests/test_guest_mode.py
similarity index 100%
rename from trio/_core/tests/test_guest_mode.py
rename to trio/_core/_tests/test_guest_mode.py
diff --git a/trio/_core/tests/test_instrumentation.py b/trio/_core/_tests/test_instrumentation.py
similarity index 100%
rename from trio/_core/tests/test_instrumentation.py
rename to trio/_core/_tests/test_instrumentation.py
diff --git a/trio/_core/tests/test_io.py b/trio/_core/_tests/test_io.py
similarity index 100%
rename from trio/_core/tests/test_io.py
rename to trio/_core/_tests/test_io.py
diff --git a/trio/_core/tests/test_ki.py b/trio/_core/_tests/test_ki.py
similarity index 100%
rename from trio/_core/tests/test_ki.py
rename to trio/_core/_tests/test_ki.py
diff --git a/trio/_core/tests/test_local.py b/trio/_core/_tests/test_local.py
similarity index 100%
rename from trio/_core/tests/test_local.py
rename to trio/_core/_tests/test_local.py
diff --git a/trio/_core/tests/test_mock_clock.py b/trio/_core/_tests/test_mock_clock.py
similarity index 100%
rename from trio/_core/tests/test_mock_clock.py
rename to trio/_core/_tests/test_mock_clock.py
diff --git a/trio/_core/tests/test_multierror.py b/trio/_core/_tests/test_multierror.py
similarity index 100%
rename from trio/_core/tests/test_multierror.py
rename to trio/_core/_tests/test_multierror.py
diff --git a/trio/_core/tests/test_multierror_scripts/__init__.py b/trio/_core/_tests/test_multierror_scripts/__init__.py
similarity index 100%
rename from trio/_core/tests/test_multierror_scripts/__init__.py
rename to trio/_core/_tests/test_multierror_scripts/__init__.py
diff --git a/trio/_core/tests/test_multierror_scripts/_common.py b/trio/_core/_tests/test_multierror_scripts/_common.py
similarity index 100%
rename from trio/_core/tests/test_multierror_scripts/_common.py
rename to trio/_core/_tests/test_multierror_scripts/_common.py
diff --git a/trio/_core/tests/test_multierror_scripts/apport_excepthook.py b/trio/_core/_tests/test_multierror_scripts/apport_excepthook.py
similarity index 100%
rename from trio/_core/tests/test_multierror_scripts/apport_excepthook.py
rename to trio/_core/_tests/test_multierror_scripts/apport_excepthook.py
diff --git a/trio/_core/tests/test_multierror_scripts/ipython_custom_exc.py b/trio/_core/_tests/test_multierror_scripts/ipython_custom_exc.py
similarity index 100%
rename from trio/_core/tests/test_multierror_scripts/ipython_custom_exc.py
rename to trio/_core/_tests/test_multierror_scripts/ipython_custom_exc.py
diff --git a/trio/_core/tests/test_multierror_scripts/simple_excepthook.py b/trio/_core/_tests/test_multierror_scripts/simple_excepthook.py
similarity index 100%
rename from trio/_core/tests/test_multierror_scripts/simple_excepthook.py
rename to trio/_core/_tests/test_multierror_scripts/simple_excepthook.py
diff --git a/trio/_core/tests/test_multierror_scripts/simple_excepthook_IPython.py b/trio/_core/_tests/test_multierror_scripts/simple_excepthook_IPython.py
similarity index 100%
rename from trio/_core/tests/test_multierror_scripts/simple_excepthook_IPython.py
rename to trio/_core/_tests/test_multierror_scripts/simple_excepthook_IPython.py
diff --git a/trio/_core/tests/test_parking_lot.py b/trio/_core/_tests/test_parking_lot.py
similarity index 100%
rename from trio/_core/tests/test_parking_lot.py
rename to trio/_core/_tests/test_parking_lot.py
diff --git a/trio/_core/tests/test_run.py b/trio/_core/_tests/test_run.py
similarity index 100%
rename from trio/_core/tests/test_run.py
rename to trio/_core/_tests/test_run.py
diff --git a/trio/_core/tests/test_thread_cache.py b/trio/_core/_tests/test_thread_cache.py
similarity index 100%
rename from trio/_core/tests/test_thread_cache.py
rename to trio/_core/_tests/test_thread_cache.py
diff --git a/trio/_core/tests/test_tutil.py b/trio/_core/_tests/test_tutil.py
similarity index 100%
rename from trio/_core/tests/test_tutil.py
rename to trio/_core/_tests/test_tutil.py
diff --git a/trio/_core/tests/test_unbounded_queue.py b/trio/_core/_tests/test_unbounded_queue.py
similarity index 100%
rename from trio/_core/tests/test_unbounded_queue.py
rename to trio/_core/_tests/test_unbounded_queue.py
diff --git a/trio/_core/tests/test_util.py b/trio/_core/_tests/test_util.py
similarity index 100%
rename from trio/_core/tests/test_util.py
rename to trio/_core/_tests/test_util.py
diff --git a/trio/_core/tests/test_windows.py b/trio/_core/_tests/test_windows.py
similarity index 100%
rename from trio/_core/tests/test_windows.py
rename to trio/_core/_tests/test_windows.py
diff --git a/trio/_core/tests/tutil.py b/trio/_core/_tests/tutil.py
similarity index 97%
rename from trio/_core/tests/tutil.py
rename to trio/_core/_tests/tutil.py
index 74760df38f..dc9a4f486d 100644
--- a/trio/_core/tests/tutil.py
+++ b/trio/_core/_tests/tutil.py
@@ -12,8 +12,8 @@
import gc
-# See trio/tests/conftest.py for the other half of this
-from trio.tests.conftest import RUN_SLOW
+# See trio/_tests/conftest.py for the other half of this
+from trio._tests.pytest_plugin import RUN_SLOW
slow = pytest.mark.skipif(not RUN_SLOW, reason="use --run-slow to run slow tests")
diff --git a/trio/_core/tests/conftest.py b/trio/_core/tests/conftest.py
deleted file mode 100644
index aca1f98a65..0000000000
--- a/trio/_core/tests/conftest.py
+++ /dev/null
@@ -1,25 +0,0 @@
-import pytest
-import inspect
-
-# XX this should move into a global something
-from ...testing import MockClock, trio_test
-
-
-@pytest.fixture
-def mock_clock():
- return MockClock()
-
-
-@pytest.fixture
-def autojump_clock():
- return MockClock(autojump_threshold=0)
-
-
-# FIXME: split off into a package (or just make part of Trio's public
-# interface?), with config file to enable? and I guess a mark option too; I
-# guess it's useful with the class- and file-level marking machinery (where
-# the raw @trio_test decorator isn't enough).
-@pytest.hookimpl(tryfirst=True)
-def pytest_pyfunc_call(pyfuncitem):
- if inspect.iscoroutinefunction(pyfuncitem.obj):
- pyfuncitem.obj = trio_test(pyfuncitem.obj)
diff --git a/trio/tests/__init__.py b/trio/_tests/__init__.py
similarity index 100%
rename from trio/tests/__init__.py
rename to trio/_tests/__init__.py
diff --git a/trio/tests/astrill-codesigning-cert.cer b/trio/_tests/astrill-codesigning-cert.cer
similarity index 100%
rename from trio/tests/astrill-codesigning-cert.cer
rename to trio/_tests/astrill-codesigning-cert.cer
diff --git a/trio/tests/module_with_deprecations.py b/trio/_tests/module_with_deprecations.py
similarity index 100%
rename from trio/tests/module_with_deprecations.py
rename to trio/_tests/module_with_deprecations.py
diff --git a/trio/tests/conftest.py b/trio/_tests/pytest_plugin.py
similarity index 93%
rename from trio/tests/conftest.py
rename to trio/_tests/pytest_plugin.py
index 772486e1eb..7ed62a1c9f 100644
--- a/trio/tests/conftest.py
+++ b/trio/_tests/pytest_plugin.py
@@ -1,5 +1,5 @@
# XX this does not belong here -- b/c it's here, these things only apply to
-# the tests in trio/_core/tests, not in trio/tests. For now there's some
+# the tests in trio/_core/_tests, not in trio/_tests. For now there's some
# copy-paste...
#
# this stuff should become a proper pytest plugin
diff --git a/trio/tests/test_abc.py b/trio/_tests/test_abc.py
similarity index 100%
rename from trio/tests/test_abc.py
rename to trio/_tests/test_abc.py
diff --git a/trio/tests/test_channel.py b/trio/_tests/test_channel.py
similarity index 100%
rename from trio/tests/test_channel.py
rename to trio/_tests/test_channel.py
diff --git a/trio/tests/test_contextvars.py b/trio/_tests/test_contextvars.py
similarity index 100%
rename from trio/tests/test_contextvars.py
rename to trio/_tests/test_contextvars.py
diff --git a/trio/tests/test_deprecate.py b/trio/_tests/test_deprecate.py
similarity index 100%
rename from trio/tests/test_deprecate.py
rename to trio/_tests/test_deprecate.py
diff --git a/trio/tests/test_dtls.py b/trio/_tests/test_dtls.py
similarity index 99%
rename from trio/tests/test_dtls.py
rename to trio/_tests/test_dtls.py
index 1420ea43d1..445ea4d1fd 100644
--- a/trio/tests/test_dtls.py
+++ b/trio/_tests/test_dtls.py
@@ -11,7 +11,7 @@
from OpenSSL import SSL
from trio.testing._fake_net import FakeNet
-from .._core.tests.tutil import slow, binds_ipv6, gc_collect_harder
+from .._core._tests.tutil import slow, binds_ipv6, gc_collect_harder
ca = trustme.CA()
server_cert = ca.issue_cert("example.com")
diff --git a/trio/tests/test_exports.py b/trio/_tests/test_exports.py
similarity index 97%
rename from trio/tests/test_exports.py
rename to trio/_tests/test_exports.py
index 8eb1131ee4..e2e0432d62 100644
--- a/trio/tests/test_exports.py
+++ b/trio/_tests/test_exports.py
@@ -24,7 +24,7 @@ def test_core_is_properly_reexported():
# three modules:
sources = [trio, trio.lowlevel, trio.testing]
for symbol in dir(_core):
- if symbol.startswith("_") or symbol == "tests":
+ if symbol.startswith("_"):
continue
found = 0
for source in sources:
@@ -47,10 +47,6 @@ def public_modules(module):
continue
if class_ is module: # pragma: no cover
continue
- # We should rename the trio.tests module (#274), but until then we use
- # a special-case hack:
- if class_.__name__ == "trio.tests":
- continue
yield from public_modules(class_)
@@ -83,11 +79,6 @@ def no_underscores(symbols):
runtime_names = no_underscores(dir(module))
- # We should rename the trio.tests module (#274), but until then we use a
- # special-case hack:
- if modname == "trio":
- runtime_names.remove("tests")
-
if tool == "pylint":
from pylint.lint import PyLinter
diff --git a/trio/tests/test_fakenet.py b/trio/_tests/test_fakenet.py
similarity index 100%
rename from trio/tests/test_fakenet.py
rename to trio/_tests/test_fakenet.py
diff --git a/trio/tests/test_file_io.py b/trio/_tests/test_file_io.py
similarity index 100%
rename from trio/tests/test_file_io.py
rename to trio/_tests/test_file_io.py
diff --git a/trio/tests/test_highlevel_generic.py b/trio/_tests/test_highlevel_generic.py
similarity index 100%
rename from trio/tests/test_highlevel_generic.py
rename to trio/_tests/test_highlevel_generic.py
diff --git a/trio/tests/test_highlevel_open_tcp_listeners.py b/trio/_tests/test_highlevel_open_tcp_listeners.py
similarity index 99%
rename from trio/tests/test_highlevel_open_tcp_listeners.py
rename to trio/_tests/test_highlevel_open_tcp_listeners.py
index 0c38b4ca69..4942f94d38 100644
--- a/trio/tests/test_highlevel_open_tcp_listeners.py
+++ b/trio/_tests/test_highlevel_open_tcp_listeners.py
@@ -11,7 +11,7 @@
from trio import open_tcp_listeners, serve_tcp, SocketListener, open_tcp_stream
from trio.testing import open_stream_to_socket_listener
from .. import socket as tsocket
-from .._core.tests.tutil import slow, creates_ipv6, binds_ipv6
+from .._core._tests.tutil import slow, creates_ipv6, binds_ipv6
if sys.version_info < (3, 11):
from exceptiongroup import BaseExceptionGroup
diff --git a/trio/tests/test_highlevel_open_tcp_stream.py b/trio/_tests/test_highlevel_open_tcp_stream.py
similarity index 100%
rename from trio/tests/test_highlevel_open_tcp_stream.py
rename to trio/_tests/test_highlevel_open_tcp_stream.py
diff --git a/trio/tests/test_highlevel_open_unix_stream.py b/trio/_tests/test_highlevel_open_unix_stream.py
similarity index 100%
rename from trio/tests/test_highlevel_open_unix_stream.py
rename to trio/_tests/test_highlevel_open_unix_stream.py
diff --git a/trio/tests/test_highlevel_serve_listeners.py b/trio/_tests/test_highlevel_serve_listeners.py
similarity index 100%
rename from trio/tests/test_highlevel_serve_listeners.py
rename to trio/_tests/test_highlevel_serve_listeners.py
diff --git a/trio/tests/test_highlevel_socket.py b/trio/_tests/test_highlevel_socket.py
similarity index 100%
rename from trio/tests/test_highlevel_socket.py
rename to trio/_tests/test_highlevel_socket.py
diff --git a/trio/tests/test_highlevel_ssl_helpers.py b/trio/_tests/test_highlevel_ssl_helpers.py
similarity index 100%
rename from trio/tests/test_highlevel_ssl_helpers.py
rename to trio/_tests/test_highlevel_ssl_helpers.py
diff --git a/trio/tests/test_path.py b/trio/_tests/test_path.py
similarity index 100%
rename from trio/tests/test_path.py
rename to trio/_tests/test_path.py
diff --git a/trio/tests/test_scheduler_determinism.py b/trio/_tests/test_scheduler_determinism.py
similarity index 100%
rename from trio/tests/test_scheduler_determinism.py
rename to trio/_tests/test_scheduler_determinism.py
diff --git a/trio/tests/test_signals.py b/trio/_tests/test_signals.py
similarity index 100%
rename from trio/tests/test_signals.py
rename to trio/_tests/test_signals.py
diff --git a/trio/tests/test_socket.py b/trio/_tests/test_socket.py
similarity index 99%
rename from trio/tests/test_socket.py
rename to trio/_tests/test_socket.py
index db21096fac..9aa18dc469 100644
--- a/trio/tests/test_socket.py
+++ b/trio/_tests/test_socket.py
@@ -8,7 +8,7 @@
import inspect
import tempfile
import sys as _sys
-from .._core.tests.tutil import creates_ipv6, binds_ipv6
+from .._core._tests.tutil import creates_ipv6, binds_ipv6
from .. import _core
from .. import _socket as _tsocket
from .. import socket as tsocket
diff --git a/trio/tests/test_ssl.py b/trio/_tests/test_ssl.py
similarity index 99%
rename from trio/tests/test_ssl.py
rename to trio/_tests/test_ssl.py
index 26e107e08f..7c63da56e8 100644
--- a/trio/tests/test_ssl.py
+++ b/trio/_tests/test_ssl.py
@@ -26,7 +26,7 @@
from .._ssl import SSLStream, SSLListener, NeedHandshakeError, _is_eof
from .._util import ConflictDetector
-from .._core.tests.tutil import slow
+from .._core._tests.tutil import slow
from ..testing import (
assert_checkpoints,
diff --git a/trio/tests/test_subprocess.py b/trio/_tests/test_subprocess.py
similarity index 99%
rename from trio/tests/test_subprocess.py
rename to trio/_tests/test_subprocess.py
index e2d66f654d..4dfaef4c7f 100644
--- a/trio/tests/test_subprocess.py
+++ b/trio/_tests/test_subprocess.py
@@ -20,7 +20,7 @@
sleep,
sleep_forever,
)
-from .._core.tests.tutil import skip_if_fbsd_pipes_broken, slow
+from .._core._tests.tutil import skip_if_fbsd_pipes_broken, slow
from ..lowlevel import open_process
from ..testing import assert_no_checkpoints, wait_all_tasks_blocked
diff --git a/trio/tests/test_sync.py b/trio/_tests/test_sync.py
similarity index 100%
rename from trio/tests/test_sync.py
rename to trio/_tests/test_sync.py
diff --git a/trio/tests/test_testing.py b/trio/_tests/test_testing.py
similarity index 99%
rename from trio/tests/test_testing.py
rename to trio/_tests/test_testing.py
index a2dba728d5..a9cc00684d 100644
--- a/trio/tests/test_testing.py
+++ b/trio/_tests/test_testing.py
@@ -4,7 +4,7 @@
import pytest
-from .._core.tests.tutil import can_bind_ipv6
+from .._core._tests.tutil import can_bind_ipv6
from .. import sleep
from .. import _core
from .._highlevel_generic import aclose_forcefully
diff --git a/trio/tests/test_threads.py b/trio/_tests/test_threads.py
similarity index 99%
rename from trio/tests/test_threads.py
rename to trio/_tests/test_threads.py
index ce852d4612..21eb7b12e8 100644
--- a/trio/tests/test_threads.py
+++ b/trio/_tests/test_threads.py
@@ -14,8 +14,8 @@
from trio._core import TrioToken, current_trio_token
from .. import CapacityLimiter, Event, _core, sleep
-from .._core.tests.test_ki import ki_self
-from .._core.tests.tutil import buggy_pypy_asyncgens
+from .._core._tests.test_ki import ki_self
+from .._core._tests.tutil import buggy_pypy_asyncgens
from .._threads import (
current_default_thread_limiter,
from_thread_run,
@@ -168,7 +168,7 @@ async def main():
async def test_named_thread():
- ending = " from trio.tests.test_threads.test_named_thread"
+ ending = " from trio._tests.test_threads.test_named_thread"
def inner(name="inner" + ending) -> threading.Thread:
assert threading.current_thread().name == name
@@ -248,7 +248,7 @@ def f(name: str) -> Callable[[None], threading.Thread]:
return partial(inner, name)
# test defaults
- default = "None from trio.tests.test_threads.test_named_thread"
+ default = "None from trio._tests.test_threads.test_named_thread"
await to_thread_run_sync(f(default))
await to_thread_run_sync(f(default), thread_name=None)
diff --git a/trio/tests/test_timeouts.py b/trio/_tests/test_timeouts.py
similarity index 98%
rename from trio/tests/test_timeouts.py
rename to trio/_tests/test_timeouts.py
index 382c015b1d..c817c49588 100644
--- a/trio/tests/test_timeouts.py
+++ b/trio/_tests/test_timeouts.py
@@ -2,7 +2,7 @@
import pytest
import time
-from .._core.tests.tutil import slow
+from .._core._tests.tutil import slow
from .. import _core
from ..testing import assert_checkpoints
from .._timeouts import *
diff --git a/trio/tests/test_tracing.py b/trio/_tests/test_tracing.py
similarity index 100%
rename from trio/tests/test_tracing.py
rename to trio/_tests/test_tracing.py
diff --git a/trio/tests/test_unix_pipes.py b/trio/_tests/test_unix_pipes.py
similarity index 99%
rename from trio/tests/test_unix_pipes.py
rename to trio/_tests/test_unix_pipes.py
index cf98942ea4..2109ab8dd2 100644
--- a/trio/tests/test_unix_pipes.py
+++ b/trio/_tests/test_unix_pipes.py
@@ -6,7 +6,7 @@
import pytest
-from .._core.tests.tutil import gc_collect_harder, skip_if_fbsd_pipes_broken
+from .._core._tests.tutil import gc_collect_harder, skip_if_fbsd_pipes_broken
from .. import _core, move_on_after
from ..testing import wait_all_tasks_blocked, check_one_way_stream
diff --git a/trio/tests/test_util.py b/trio/_tests/test_util.py
similarity index 99%
rename from trio/tests/test_util.py
rename to trio/_tests/test_util.py
index 15ab09a80b..9f89a68efe 100644
--- a/trio/tests/test_util.py
+++ b/trio/_tests/test_util.py
@@ -5,7 +5,7 @@
import trio
from .. import _core
-from .._core.tests.tutil import (
+from .._core._tests.tutil import (
ignore_coroutine_never_awaited_warnings,
create_asyncio_future_in_new_loop,
)
diff --git a/trio/tests/test_wait_for_object.py b/trio/_tests/test_wait_for_object.py
similarity index 99%
rename from trio/tests/test_wait_for_object.py
rename to trio/_tests/test_wait_for_object.py
index 38acfa802d..54291444a0 100644
--- a/trio/tests/test_wait_for_object.py
+++ b/trio/_tests/test_wait_for_object.py
@@ -6,7 +6,7 @@
# Mark all the tests in this file as being windows-only
pytestmark = pytest.mark.skipif(not on_windows, reason="windows only")
-from .._core.tests.tutil import slow
+from .._core._tests.tutil import slow
import trio
from .. import _core
from .. import _timeouts
diff --git a/trio/tests/test_windows_pipes.py b/trio/_tests/test_windows_pipes.py
similarity index 98%
rename from trio/tests/test_windows_pipes.py
rename to trio/_tests/test_windows_pipes.py
index 2bcc64a072..4443cc0a2f 100644
--- a/trio/tests/test_windows_pipes.py
+++ b/trio/_tests/test_windows_pipes.py
@@ -8,7 +8,7 @@
import pytest
-from .._core.tests.tutil import gc_collect_harder
+from .._core._tests.tutil import gc_collect_harder
from .. import _core, move_on_after
from ..testing import wait_all_tasks_blocked, check_one_way_stream
diff --git a/trio/tests/tools/__init__.py b/trio/_tests/tools/__init__.py
similarity index 100%
rename from trio/tests/tools/__init__.py
rename to trio/_tests/tools/__init__.py
diff --git a/trio/tests/tools/test_gen_exports.py b/trio/_tests/tools/test_gen_exports.py
similarity index 100%
rename from trio/tests/tools/test_gen_exports.py
rename to trio/_tests/tools/test_gen_exports.py
diff --git a/trio/tests.py b/trio/tests.py
new file mode 100644
index 0000000000..ad31bf6602
--- /dev/null
+++ b/trio/tests.py
@@ -0,0 +1,10 @@
+from ._deprecate import warn_deprecated
+import trio
+from ._tests import *
+
+warn_deprecated(
+ trio.tests,
+ "0.23.0",
+ instead=trio._tests,
+ issue="https://github.com/python-trio/trio/issues/274",
+)
From 26d9f6e808186726dd3a33e9d42f6301c6a80026 Mon Sep 17 00:00:00 2001
From: jakkdl
Date: Mon, 17 Apr 2023 13:28:10 +0200
Subject: [PATCH 2/4] add trio.tests module that raises deprecationwarning, add
tests
---
trio/__init__.py | 1 +
trio/_tests/pytest_plugin.py | 6 ------
trio/_tests/test_deprecate.py | 12 +++++++++++
trio/_tests/test_exports.py | 4 ++--
trio/tests.py | 40 +++++++++++++++++++++++++++++------
5 files changed, 48 insertions(+), 15 deletions(-)
diff --git a/trio/__init__.py b/trio/__init__.py
index d6d2adb4bb..c561c65bb4 100644
--- a/trio/__init__.py
+++ b/trio/__init__.py
@@ -100,6 +100,7 @@
from . import abc
from . import from_thread
from . import to_thread
+from . import tests # deprecated
# Not imported by default, but mentioned here so static analysis tools like
# pylint will know that it exists.
diff --git a/trio/_tests/pytest_plugin.py b/trio/_tests/pytest_plugin.py
index 7ed62a1c9f..a893b466cb 100644
--- a/trio/_tests/pytest_plugin.py
+++ b/trio/_tests/pytest_plugin.py
@@ -1,9 +1,3 @@
-# XX this does not belong here -- b/c it's here, these things only apply to
-# the tests in trio/_core/_tests, not in trio/_tests. For now there's some
-# copy-paste...
-#
-# this stuff should become a proper pytest plugin
-
import pytest
import inspect
diff --git a/trio/_tests/test_deprecate.py b/trio/_tests/test_deprecate.py
index e5e1da8c5f..8a6b812a0a 100644
--- a/trio/_tests/test_deprecate.py
+++ b/trio/_tests/test_deprecate.py
@@ -241,3 +241,15 @@ def test_module_with_deprecations(recwarn_always):
with pytest.raises(AttributeError):
module_with_deprecations.asdf
+
+
+def test_tests_is_deprecated() -> None:
+ from trio import tests
+
+ with pytest.warns(TrioDeprecationWarning):
+ tests.test_abc # type: ignore[attr-defined]
+
+ with pytest.warns(TrioDeprecationWarning):
+ import trio.tests
+
+ trio.tests.test_deprecate # type: ignore[attr-defined]
diff --git a/trio/_tests/test_exports.py b/trio/_tests/test_exports.py
index e2e0432d62..71c32464a0 100644
--- a/trio/_tests/test_exports.py
+++ b/trio/_tests/test_exports.py
@@ -13,10 +13,10 @@
import trio
import trio.testing
-from trio.tests.conftest import RUN_SLOW
from .. import _core, _util
-from .._core.tests.tutil import slow
+from .._core._tests.tutil import slow
+from .pytest_plugin import RUN_SLOW
def test_core_is_properly_reexported():
diff --git a/trio/tests.py b/trio/tests.py
index ad31bf6602..51cb247218 100644
--- a/trio/tests.py
+++ b/trio/tests.py
@@ -1,10 +1,36 @@
+import importlib
+import sys
+from typing import Any
+
+# don't ask which of the _tests imports is necessary
+import trio._tests
+
+from . import _tests
from ._deprecate import warn_deprecated
-import trio
from ._tests import *
-warn_deprecated(
- trio.tests,
- "0.23.0",
- instead=trio._tests,
- issue="https://github.com/python-trio/trio/issues/274",
-)
+
+# This won't give deprecation warning on import, but will give a warning on use of any
+# attribute in tests, and static analysis tools will also not see any content inside.
+class TestsDeprecationWrapper:
+ __name__ = "trio.tests"
+
+ def __getattr__(self, attr: str) -> Any:
+ warn_deprecated(
+ f"trio.tests.{attr}",
+ "0.24.0",
+ instead=f"trio._tests.{attr}",
+ issue="https://github.com/python-trio/trio/issues/274",
+ )
+
+ # idk if this one is necessary, apparently doesn't get triggered by codecov
+ # but I needed it when running tests locally at some point
+ if not hasattr(trio._tests, attr): # pragma: no cover
+ importlib.import_module(f"trio._tests.{attr}", "trio._tests")
+ return attr
+
+ return getattr(trio._tests, attr)
+
+
+# https://stackoverflow.com/questions/2447353/getattr-on-a-module
+sys.modules[__name__] = TestsDeprecationWrapper() # type: ignore[assignment]
From 0b5d131f00c63167f68bc90bae361122a29e36cb Mon Sep 17 00:00:00 2001
From: jakkdl
Date: Thu, 18 May 2023 14:08:18 +0200
Subject: [PATCH 3/4] remove unnecessary imports, refactor tests, improve
comments
---
trio/_tests/test_deprecate.py | 24 ++++++++++++++++++++----
trio/tests.py | 11 +++--------
2 files changed, 23 insertions(+), 12 deletions(-)
diff --git a/trio/_tests/test_deprecate.py b/trio/_tests/test_deprecate.py
index 8a6b812a0a..2a09e14b74 100644
--- a/trio/_tests/test_deprecate.py
+++ b/trio/_tests/test_deprecate.py
@@ -243,13 +243,29 @@ def test_module_with_deprecations(recwarn_always):
module_with_deprecations.asdf
-def test_tests_is_deprecated() -> None:
- from trio import tests
+def test_tests_is_deprecated1() -> None:
+ from trio import tests # no warning on import
+ # warning on access of any member
with pytest.warns(TrioDeprecationWarning):
- tests.test_abc # type: ignore[attr-defined]
+ assert tests.test_abc # type: ignore[attr-defined]
+
+def test_tests_is_deprecated2() -> None:
+ # warning on direct import of test since that accesses `__spec__`
with pytest.warns(TrioDeprecationWarning):
import trio.tests
- trio.tests.test_deprecate # type: ignore[attr-defined]
+ with pytest.warns(TrioDeprecationWarning):
+ assert trio.tests.test_deprecate # type: ignore[attr-defined]
+
+
+def test_tests_is_deprecated3() -> None:
+ import trio
+
+ # no warning on accessing the submodule
+ assert trio.tests
+
+ # only when accessing a submodule member
+ with pytest.warns(TrioDeprecationWarning):
+ assert trio.tests.test_abc # type: ignore[attr-defined]
diff --git a/trio/tests.py b/trio/tests.py
index 51cb247218..1dc0825f2c 100644
--- a/trio/tests.py
+++ b/trio/tests.py
@@ -2,12 +2,8 @@
import sys
from typing import Any
-# don't ask which of the _tests imports is necessary
-import trio._tests
-
from . import _tests
from ._deprecate import warn_deprecated
-from ._tests import *
# This won't give deprecation warning on import, but will give a warning on use of any
@@ -23,13 +19,12 @@ def __getattr__(self, attr: str) -> Any:
issue="https://github.com/python-trio/trio/issues/274",
)
- # idk if this one is necessary, apparently doesn't get triggered by codecov
- # but I needed it when running tests locally at some point
- if not hasattr(trio._tests, attr): # pragma: no cover
+ # needed to access e.g. trio._tests.tools, although pytest doesn't need it
+ if not hasattr(_tests, attr): # pragma: no cover
importlib.import_module(f"trio._tests.{attr}", "trio._tests")
return attr
- return getattr(trio._tests, attr)
+ return getattr(_tests, attr)
# https://stackoverflow.com/questions/2447353/getattr-on-a-module
From 1b422767aa7797259764f1625808a0fb2cee3c3f Mon Sep 17 00:00:00 2001
From: jakkdl
Date: Mon, 22 May 2023 10:38:04 +0200
Subject: [PATCH 4/4] now also warns on `from trio import tests`
---
trio/__init__.py | 1 -
trio/_tests/test_deprecate.py | 3 ++-
trio/_tests/test_exports.py | 8 ++++++++
trio/tests.py | 7 +++++++
4 files changed, 17 insertions(+), 2 deletions(-)
diff --git a/trio/__init__.py b/trio/__init__.py
index c561c65bb4..d6d2adb4bb 100644
--- a/trio/__init__.py
+++ b/trio/__init__.py
@@ -100,7 +100,6 @@
from . import abc
from . import from_thread
from . import to_thread
-from . import tests # deprecated
# Not imported by default, but mentioned here so static analysis tools like
# pylint will know that it exists.
diff --git a/trio/_tests/test_deprecate.py b/trio/_tests/test_deprecate.py
index 2a09e14b74..856ff20673 100644
--- a/trio/_tests/test_deprecate.py
+++ b/trio/_tests/test_deprecate.py
@@ -244,7 +244,8 @@ def test_module_with_deprecations(recwarn_always):
def test_tests_is_deprecated1() -> None:
- from trio import tests # no warning on import
+ with pytest.warns(TrioDeprecationWarning):
+ from trio import tests # warning on import
# warning on access of any member
with pytest.warns(TrioDeprecationWarning):
diff --git a/trio/_tests/test_exports.py b/trio/_tests/test_exports.py
index 71c32464a0..2fd8362193 100644
--- a/trio/_tests/test_exports.py
+++ b/trio/_tests/test_exports.py
@@ -79,6 +79,10 @@ def no_underscores(symbols):
runtime_names = no_underscores(dir(module))
+ # ignore deprecated module `tests` being invisible
+ if modname == "trio":
+ runtime_names.discard("tests")
+
if tool == "pylint":
from pylint.lint import PyLinter
@@ -133,6 +137,10 @@ def no_underscores(symbols):
# static analysis (e.g. in trio.socket or trio.lowlevel)
# So we check that the runtime names are a subset of the static names.
missing_names = runtime_names - static_names
+
+ # ignore warnings about deprecated module tests
+ missing_names -= {"tests"}
+
if missing_names: # pragma: no cover
print(f"{tool} can't see the following names in {modname}:")
print()
diff --git a/trio/tests.py b/trio/tests.py
index 1dc0825f2c..f1940a6929 100644
--- a/trio/tests.py
+++ b/trio/tests.py
@@ -5,6 +5,13 @@
from . import _tests
from ._deprecate import warn_deprecated
+warn_deprecated(
+ "trio.tests",
+ "0.24.0",
+ instead="trio._tests",
+ issue="https://github.com/python-trio/trio/issues/274",
+)
+
# This won't give deprecation warning on import, but will give a warning on use of any
# attribute in tests, and static analysis tools will also not see any content inside.