From 9cda20bbb966fe1e4ae51921d566c668654ee5e1 Mon Sep 17 00:00:00 2001 From: Vincent Vanlaer Date: Sun, 3 Sep 2023 00:00:54 +0200 Subject: [PATCH 1/2] Remove trio.tests import causing warnings It is deprecated and the replacement is made private as trio._tests. While we could be using that, this commit copies over the one relevant function that is actually necessary. The other two imports just repeat tests that are already in trio and do not need repeating here. --- .../_tests/test_hypothesis_interaction.py | 21 ++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/pytest_trio/_tests/test_hypothesis_interaction.py b/pytest_trio/_tests/test_hypothesis_interaction.py index 75aa9f7..cb95a96 100644 --- a/pytest_trio/_tests/test_hypothesis_interaction.py +++ b/pytest_trio/_tests/test_hypothesis_interaction.py @@ -1,10 +1,5 @@ import pytest import trio -from trio.tests.test_scheduler_determinism import ( - scheduler_trace, - test_the_trio_scheduler_is_not_deterministic, - test_the_trio_scheduler_is_deterministic_if_seeded, -) from hypothesis import given, settings, strategies as st from pytest_trio.plugin import _trio_test_runner_factory @@ -38,6 +33,22 @@ async def test_mark_and_parametrize(x, y): assert y in (1, 2) +async def scheduler_trace(): + """Returns a scheduler-dependent value we can use to check determinism.""" + trace = [] + + async def tracer(name): + for i in range(10): + trace.append((name, i)) + await trio.sleep(0) + + async with trio.open_nursery() as nursery: + for i in range(5): + nursery.start_soon(tracer, i) + + return tuple(trace) + + def test_the_trio_scheduler_is_deterministic_under_hypothesis(): traces = [] From 788fee31d2bc3a9ee659dfce6162b3c0cf9d6a80 Mon Sep 17 00:00:00 2001 From: Vincent Vanlaer Date: Sun, 3 Sep 2023 00:16:47 +0200 Subject: [PATCH 2/2] Fix black changes --- docs/source/conf.py | 1 + pytest_trio/_tests/test_async_fixture.py | 5 ----- pytest_trio/_tests/test_async_yield_fixture.py | 6 ------ pytest_trio/_tests/test_basic.py | 4 ---- pytest_trio/_tests/test_sync_fixture.py | 3 --- 5 files changed, 1 insertion(+), 18 deletions(-) diff --git a/docs/source/conf.py b/docs/source/conf.py index 7a71ac8..ff74f8b 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -45,6 +45,7 @@ ("py:obj", "bytes-like"), ] + # XX hack the RTD theme until # https://github.com/rtfd/sphinx_rtd_theme/pull/382 # is shipped (should be in the release after 0.2.4) diff --git a/pytest_trio/_tests/test_async_fixture.py b/pytest_trio/_tests/test_async_fixture.py index 88c4aa9..3703f73 100644 --- a/pytest_trio/_tests/test_async_fixture.py +++ b/pytest_trio/_tests/test_async_fixture.py @@ -2,7 +2,6 @@ def test_single_async_fixture(testdir): - testdir.makepyfile( """ import pytest @@ -25,7 +24,6 @@ async def test_simple(fix1): def test_async_fixture_recomputed_for_each_test(testdir): - testdir.makepyfile( """ import pytest @@ -56,7 +54,6 @@ async def test_second(fix1): def test_nested_async_fixture(testdir): - testdir.makepyfile( """ import pytest @@ -89,7 +86,6 @@ async def test_both(fix1, fix2): def test_async_within_sync_fixture(testdir): - testdir.makepyfile( """ import pytest @@ -122,7 +118,6 @@ async def test_simple(sync_fix): # async fixture... @pytest.mark.xfail(reason="Not implemented yet") def test_raise_in_async_fixture_cause_pytest_error(testdir): - testdir.makepyfile( """ import pytest diff --git a/pytest_trio/_tests/test_async_yield_fixture.py b/pytest_trio/_tests/test_async_yield_fixture.py index ca99159..9505eb2 100644 --- a/pytest_trio/_tests/test_async_yield_fixture.py +++ b/pytest_trio/_tests/test_async_yield_fixture.py @@ -38,7 +38,6 @@ def test_after(): def test_nested_async_yield_fixture(testdir): - testdir.makepyfile( """ import pytest @@ -93,7 +92,6 @@ def test_after(): def test_async_yield_fixture_within_sync_fixture(testdir): - testdir.makepyfile( """ import pytest @@ -139,7 +137,6 @@ def test_after(): def test_async_yield_fixture_within_sync_yield_fixture(testdir): - testdir.makepyfile( """ import pytest @@ -190,7 +187,6 @@ def test_after(): def test_async_yield_fixture_with_multiple_yields(testdir): - testdir.makepyfile( """ import pytest @@ -217,7 +213,6 @@ async def test_actual_test(fix1): def test_async_yield_fixture_with_nursery(testdir): - testdir.makepyfile( """ import pytest @@ -253,7 +248,6 @@ async def test_actual_test(server): def test_async_yield_fixture_crashed_teardown_allow_other_teardowns(testdir): - testdir.makepyfile( """ import pytest diff --git a/pytest_trio/_tests/test_basic.py b/pytest_trio/_tests/test_basic.py index 9702498..f95538f 100644 --- a/pytest_trio/_tests/test_basic.py +++ b/pytest_trio/_tests/test_basic.py @@ -2,7 +2,6 @@ def test_async_test_is_executed(testdir): - testdir.makepyfile( """ import pytest @@ -27,7 +26,6 @@ def test_check_async_test_called(): def test_async_test_as_class_method(testdir): - testdir.makepyfile( """ import pytest @@ -60,7 +58,6 @@ def test_check_async_test_called(): @pytest.mark.xfail(reason="Raises pytest internal error so far...") def test_sync_function_with_trio_mark(testdir): - testdir.makepyfile( """ import pytest @@ -77,7 +74,6 @@ def test_invalid(): def test_skip_and_xfail(testdir): - testdir.makepyfile( """ import functools diff --git a/pytest_trio/_tests/test_sync_fixture.py b/pytest_trio/_tests/test_sync_fixture.py index 738ffbc..c6060a4 100644 --- a/pytest_trio/_tests/test_sync_fixture.py +++ b/pytest_trio/_tests/test_sync_fixture.py @@ -12,7 +12,6 @@ async def test_single_sync_fixture(sync_fix): def test_single_yield_fixture(testdir): - testdir.makepyfile( """ import pytest @@ -47,7 +46,6 @@ def test_after(): def test_single_yield_fixture_with_async_deps(testdir): - testdir.makepyfile( """ import pytest @@ -90,7 +88,6 @@ def test_after(): def test_sync_yield_fixture_crashed_teardown_allow_other_teardowns(testdir): - testdir.makepyfile( """ import pytest