-
Notifications
You must be signed in to change notification settings - Fork 631
Separate testing utils from tests #2225
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
@flying-sheep, do you know of a large package (ideally in our dependencies) which uses the directory structure you're advocating for? I'd ideally like to have another repo to look at/ crib from for test organization strategies. |
Most things?
They both have |
Oh, I specifically meant Though looking through the pandas test it does look like there are fewer internal imports than I recall. |
As said:
|
Could you point some projects who's testing layout you'd like to emulate? I'd ideally like to have something to look at for reference. I would also like something I could try out, since I recall "acceptable test discovery arguments" can be a bit fiddly with pytest. For modules of test utils, I think I'd go |
I literally never had problems with test discovery, so idk what to look for. As said: Numpy and pandas have separated their testing utils from their tests. For the time being I want just that, no change to where the tests are. Would you accept a PR that simply moves the test utils into private submodules of Any change to the test layout can come later or never. I’d like to follow pytest’s recommendation ( |
Can you point to a package whose test organization you would like our tests to emulate? I find pytests docs rather hard to navigate and would really prefer to see an example of what you're advocating for. From your description above I had thought you didn't want to emulate pandas use of conftest.
I'd lean towards it, but I fully expect issues like #685 to come up. This is why I'd like to see a working example of what you want to work towards.
Is it definitely the future default? It looks like they are walking that back. Current versions of pytest docs say:
Where it previously said: |
The others have their tests in the package, and just have that useless
What do you mean specifically? Pandas are defining special pytest functions/variables there and fixtures, which is what it’s for. I’d probably judge that we don’t need all those fixtures for our complete test suite and move some of them to a smaller scope (e.g.
Actually I think we can fix that: the docs for
The question is if they remove the others or not, I think: pytest-dev/pytest#7245 My intention here is to make clear which code lives under which laws. Pytest world is very different from Python module world. The presence of
accepting that makes it easier to reason about how our test suite works. |
I'm not sure that pytest issue convinced me importlib is a good thing... A few of the recent pytest developer comments that caught my eye were:
I would be up for a PR that only moved things outside of the test module. Things that would probably slow down or prevent merging would include:
All of these things seem like they can be done in other PRs easily after test utilities are moved. Right? |
I’m pretty happy with #2235 for several reasons. Let’s call! |
Pytest supports two test layouts, in-package and outside-of-package. I prefer the outside-of-package mode outlined here: https://docs.pytest.org/en/6.2.x/goodpractices.html
Scanpy currently mixes test utils with tests, but pytest’s test files (
test_*.py
andconftest.py
) aren’t Python modules one is supposed to import from.To clean things up, we can refactor scanpy to a in-package structure:
pyproject.toml
: addaddopts = ['--import-mode=importlib']
to[tool.pytest.ini_options]
scanpy/tests/__init__.py
during implementation, make it throw an error on import so we can make sure nobody imports things from there, then deletescanpy/tests/**/__init__.py
deletescanpy/test_utils/
orscanpy/testing/
__init__.py
: leave empty for now, later add public, documented test utils_private.py
add private test utils that can be imported in our tests, such as the@needs_somepackage
decoratorsLater we can decide if we want to keep the in-package layout or switch to the outside-of-package layout
The text was updated successfully, but these errors were encountered: