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 80% rename from trio/tests/conftest.py rename to trio/_tests/pytest_plugin.py index 772486e1eb..a893b466cb 100644 --- a/trio/tests/conftest.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_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 88% rename from trio/tests/test_deprecate.py rename to trio/_tests/test_deprecate.py index e5e1da8c5f..856ff20673 100644 --- a/trio/tests/test_deprecate.py +++ b/trio/_tests/test_deprecate.py @@ -241,3 +241,32 @@ def test_module_with_deprecations(recwarn_always): with pytest.raises(AttributeError): module_with_deprecations.asdf + + +def test_tests_is_deprecated1() -> None: + with pytest.warns(TrioDeprecationWarning): + from trio import tests # warning on import + + # warning on access of any member + with pytest.warns(TrioDeprecationWarning): + 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 + + 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/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 96% rename from trio/tests/test_exports.py rename to trio/_tests/test_exports.py index 8eb1131ee4..2fd8362193 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(): @@ -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,10 +79,9 @@ 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: + # ignore deprecated module `tests` being invisible if modname == "trio": - runtime_names.remove("tests") + runtime_names.discard("tests") if tool == "pylint": from pylint.lint import PyLinter @@ -142,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/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..f1940a6929 --- /dev/null +++ b/trio/tests.py @@ -0,0 +1,38 @@ +import importlib +import sys +from typing import Any + +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. +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", + ) + + # 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(_tests, attr) + + +# https://stackoverflow.com/questions/2447353/getattr-on-a-module +sys.modules[__name__] = TestsDeprecationWrapper() # type: ignore[assignment]