Skip to content

Conversation

@jakkdl
Copy link
Member

@jakkdl jakkdl commented Apr 5, 2023

Simply renames the directories trio/tests and trio/_core/tests, and updates references to them.

Addresses some (or all?) problems in #274
Fixes the second task in #2625

@njsmith - especially wrt to considerations for #274

@jakkdl
Copy link
Member Author

jakkdl commented Apr 5, 2023

ah, trio/_tests/conftest.py is not parsed for CLI flags (i.e. --runslow) before running. Could e.g. solve that by moving conftest.py into trio/, but that'd make it public.
There's probably other ways of achieving it ... but it's surprisingly tricky, and I've yet to manage something else decent

@A5rocks
Copy link
Contributor

A5rocks commented Apr 5, 2023

I poked at this a bit and adding -p "trio._tests.conftest" seems to get further -- until it complains about adding the plugin twice (second time as normal part of test discovery).

Like the comment in the file says, we can essentially put trio._tests.conftest (which contains all of trio._core._tests.conftest) into a plugin and that'll work fine.

@jakkdl
Copy link
Member Author

jakkdl commented Apr 7, 2023

I poked at this a bit and adding -p "trio._tests.conftest" seems to get further -- until it complains about adding the plugin twice (second time as normal part of test discovery).

Like the comment in the file says, we can essentially put trio._tests.conftest (which contains all of trio._core._tests.conftest) into a plugin and that'll work fine.

huh, I don't get that far:

  File "/home/h/Git/trio/trio/_tests/conftest.py", line 10, in <module>
    from ..testing import trio_test, MockClock
  File "/home/h/Git/trio/trio/testing/__init__.py", line 7, in <module>
    from ._sequencer import Sequencer
  File "/home/h/Git/trio/trio/testing/_sequencer.py", line 11, in <module>
    from .. import Event
ImportError: Error importing plugin "trio._tests.conftest": cannot import name 'Event' from 'trio' (unknown location)

though maybe I've messed up my environment somehow. Feel free to push a commit that makes it a plugin if you can get it to work.

@A5rocks
Copy link
Contributor

A5rocks commented Apr 12, 2023

I should probably mention this now before I forget: we should have a dummy tests.py or something that has a from ._tests import * (or the like, as long as it doesn't re-export for pyright) and a deprecation. Breaking changes are bad, even if we expect nobody uses this.

@codecov
Copy link

codecov bot commented Apr 13, 2023

Codecov Report

Merging #2628 (1b42276) into master (855f5fd) will decrease coverage by 0.73%.
The diff coverage is 100.00%.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #2628      +/-   ##
==========================================
- Coverage   92.46%   91.73%   -0.73%     
==========================================
  Files         118      118              
  Lines       16431    16444      +13     
  Branches     2970     2970              
==========================================
- Hits        15193    15085     -108     
- Misses       1124     1244     +120     
- Partials      114      115       +1     
Impacted Files Coverage Δ
trio/_core/_tests/test_asyncgen.py 99.06% <ø> (ø)
trio/_core/_tests/test_guest_mode.py 99.65% <ø> (ø)
trio/_core/_tests/test_instrumentation.py 100.00% <ø> (ø)
trio/_core/_tests/test_io.py 98.24% <ø> (ø)
trio/_core/_tests/test_ki.py 97.83% <ø> (ø)
trio/_core/_tests/test_local.py 100.00% <ø> (ø)
trio/_core/_tests/test_mock_clock.py 100.00% <ø> (ø)
trio/_core/_tests/test_multierror.py 100.00% <ø> (ø)
...io/_core/_tests/test_multierror_scripts/_common.py 100.00% <ø> (ø)
...tests/test_multierror_scripts/apport_excepthook.py 100.00% <ø> (ø)
... and 44 more

... and 7 files with indirect coverage changes

@jakkdl
Copy link
Member Author

jakkdl commented Apr 13, 2023

I'm still having some env issues with running the tests myself sometimes, but they seem to pass CI - so it should be fine on a clean install.

Added trio/tests.py and guessed how it was supposed to look :)

Copy link
Contributor

@A5rocks A5rocks left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Presumably doing import trio.tests will work as a test but I don't think we need one.

@jakkdl jakkdl force-pushed the import_as branch 2 times, most recently from 1725f04 to 92ae278 Compare April 17, 2023 12:24
@jakkdl
Copy link
Member Author

jakkdl commented Apr 17, 2023

Cleaned up and added an import+deprecation test.
I'm a bit confused about codecov wrt trio.testing, but I don't think it's a problem?

Formatting seems to have hit a snag with ... something unrelated to this PR.
and 3.12 continues to fail like usual.

@jakkdl
Copy link
Member Author

jakkdl commented May 5, 2023

@A5rocks this one is also ready for review

Copy link
Contributor

@A5rocks A5rocks left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursory review comments, I might find something else in a second review!

trio/tests.py Outdated
def __getattr__(self, attr: str) -> Any:
warn_deprecated(
f"trio.tests.{attr}",
"0.23.0",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm decently sure this deprecation should be kicked off until 0.24.0 -- this will probably get out in a 0.22.0 that removes support for Python 3.7 which will be a major (-> minor cause 0.) bump.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good, I just copy-pasted another deprecation warning without considering the versioning :)

@A5rocks
Copy link
Contributor

A5rocks commented May 15, 2023

FYI master fixes the CI runs, so just merge that in!

@jakkdl jakkdl force-pushed the import_as branch 2 times, most recently from c12ce07 to 6be34f3 Compare May 16, 2023 10:15
@jakkdl
Copy link
Member Author

jakkdl commented May 16, 2023

rebased on top of master, and fixed review comments

@jakkdl
Copy link
Member Author

jakkdl commented May 16, 2023

I'm a bit confused about codecov wrt trio.testing, but I don't think it's a problem?

Ah. Codecov doesn't see them anymore because trio._tests.pytest_plugin is run with pytest -p, and that must be before codecov gets activated. That's also the first time testing is imported, so on subsequent imports python doesn't reparse what was already covered when pytest_plugin imported it - and codecov therefore doesn't see it.

So we should maybe switch to starting coverage before pytest? https://stackoverflow.com/a/62224494
i.e. switch to coverage run -m pytest ....
I think that would solve the issue

@A5rocks
Copy link
Contributor

A5rocks commented May 16, 2023

Sounds good, we want to redo codecov a bit too since it doesn't work with like Windows and whatever ATM. So feel free to change things slightly if necessary!

@jakkdl jakkdl force-pushed the import_as branch 2 times, most recently from ce7fddc to 00fe706 Compare May 17, 2023 14:38
@jakkdl
Copy link
Member Author

jakkdl commented May 17, 2023

uh, looks like codecov isn't turning up as a check at all now. I'll just revert it and we can put a pin into running with codecov -m for the upcoming codecov changes in a separate PR. I'd like this merged so it stops blocking #2629

Copy link
Contributor

@A5rocks A5rocks left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks mostly good, I'd like @njsmith to weigh in cause I'm not too used to changes like this!

trio/tests.py Outdated
Comment on lines 5 to 8
# don't ask which of the _tests imports is necessary
import trio._tests

from . import _tests
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm a bit confused by this, won't the namespaces shadow and so the first is useless?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't you see the comment?? 😂
I don't remember what caused the confusion back when I was messing around with it. Neither is technically useless atm, as they import the same package as different names. Removing the latter makes no difference to functionality, and removing the first one requires exchanging references to trio._tests to be _tests. But importing from the local package seems superior, so I'll do the latter.

@jakkdl
Copy link
Member Author

jakkdl commented May 18, 2023

Fixed review comments, removing unnecessary imports. And reading the PR after having forgotten what the code does unsurprisingly lead to some improved comments and tests 😇



# https://stackoverflow.com/questions/2447353/getattr-on-a-module
sys.modules[__name__] = TestsDeprecationWrapper() # type: ignore[assignment]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure we really need to be this careful about backcompat here -- surely people aren't actually using trio.tests, right? -- but I guess it's harmless.

Though... I guess we actually want to get rid of trio.tests entirely, so maybe we should issue the warning on import? If someone is importing it but not using it (for some reason), then they won't get a warning, but they'll still get broken in the future when we delete this file.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah, took me a minute but figured out how to get it to warn on import as well. Only thing it doesn't warn on now that would break is import trio; assert trio.tests - i.e. access of the module, but without importing it, and not accessing any of it's attributes. (I tried changing from using __getattr__ to __getattribute__ but that made no difference in this case). There's probably some way of addressing that, but now we're getting into very weird cases.

@jakkdl jakkdl force-pushed the import_as branch 2 times, most recently from a74edda to 915c22c Compare May 22, 2023 10:01
@jakkdl
Copy link
Member Author

jakkdl commented May 22, 2023

removed the test import from __init__.py, so it's now also invisible to static analysis. Added a corresponding exception for it being a missing symbols in the static analysis tests.

@jakkdl
Copy link
Member Author

jakkdl commented May 24, 2023

@A5rocks any reservations about merging this?

@A5rocks A5rocks merged commit ef06fba into python-trio:master May 24, 2023
@A5rocks A5rocks mentioned this pull request May 24, 2023
@jakkdl jakkdl deleted the import_as branch May 24, 2023 15:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants