Skip to content

Conversation

@vyasr
Copy link
Contributor

@vyasr vyasr commented Jun 10, 2025

Contributes to rapidsai/build-planning#105

To make this work, I had to run all tests with pytest's --import-mode=append argument to get around issues with the new default importlib mode. That also necessitated moving the tests out of the cuml package source directory to avoid conflicts, then adding __init__.py files to each of the test directories to avoid import conflicts with the various conftest.py files.

@vyasr vyasr self-assigned this Jun 10, 2025
@vyasr vyasr requested a review from a team as a code owner June 10, 2025 16:55
@vyasr vyasr added the improvement Improvement / enhancement to an existing function label Jun 10, 2025
@vyasr vyasr requested a review from raydouglass June 10, 2025 16:55
@vyasr vyasr added the non-breaking Non-breaking change label Jun 10, 2025
@github-actions github-actions bot added conda conda issue Cython / Python Cython or Python issue labels Jun 10, 2025
@betatim
Copy link
Member

betatim commented Jun 27, 2025

If merging in branch-25.08 doesn't fix the CI it would be great if you could investigate what is going wrong

@vyasr
Copy link
Contributor Author

vyasr commented Jul 15, 2025

I'm afraid I haven't had time to look into this yet, and I probably won't for a while. @csadorf if you think this is important we may need to coordinate a handoff to get it in sooner. Otherwise I'll get around to it when I can.

@csadorf
Copy link
Contributor

csadorf commented Jul 16, 2025

I'm afraid I haven't had time to look into this yet, and I probably won't for a while. @csadorf if you think this is important we may need to coordinate a handoff to get it in sooner. Otherwise I'll get around to it when I can.

I don't think it's very urgent at the moment. I am going to preemptively target this for 25.10.

@vyasr vyasr changed the base branch from branch-25.08 to branch-25.10 July 25, 2025 18:31
@vyasr vyasr requested review from a team as code owners July 28, 2025 15:20
@vyasr vyasr requested review from divyegala, gforsyth and tfeher and removed request for raydouglass July 28, 2025 15:20
@vyasr vyasr force-pushed the chore/remove_pytest_pin branch from 30211b2 to 7fd3f28 Compare July 28, 2025 15:55
@github-actions github-actions bot added the ci label Jul 29, 2025
@vyasr vyasr requested a review from a team as a code owner July 29, 2025 20:54
@vyasr vyasr requested a review from bdice July 29, 2025 20:54
@betatim
Copy link
Member

betatim commented Jul 31, 2025

Came here to merge this but between the last time I looked at this and now it seems the scope grew quite a bit. It went from "let's remove the pin" to a whole sale reorganisation of the testing.

It is not clear to me why cuml is special in the sense that we need to specify --import-mode and move the tests around. Surely the fundamentals of how pytest works have not changed so much. I've not seen other projects move around their test suites etc either.

The docs say that prepend was and is the default mode, so why do we need to change? Do we have to specify the import mode on the command-line or can it be put in a config file. The more options that are needed on the CLI the more difficult it is to run tests locally, because you need to remember the bespoke incantation instead of simply running pytest test_the_file_with_test_I_want_to_run.py

Overall, there must be a better way. The way to run tests is already pretty convoluted (compared to industry standard "run pytest in the git repo, see results") and this feels like it is adding more layers without a lot of explanation for people from the future as to why and how/when you can remove them again.

@csadorf csadorf added the DO NOT MERGE Hold off on merging; see PR for details label Jul 31, 2025
@csadorf csadorf self-requested a review July 31, 2025 15:49
Copy link
Contributor

@csadorf csadorf left a comment

Choose a reason for hiding this comment

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

Considering the extent and scope of this PR, I'd like to review this before merge.

@csadorf
Copy link
Contributor

csadorf commented Jul 31, 2025

@vyasr Can you make sure that the PR title represents the changes here?

@vyasr
Copy link
Contributor Author

vyasr commented Jul 31, 2025

Surely the fundamentals of how pytest works have not changed so much. I've not seen other projects move around their test suites etc either.

cuml is not special. We already have this set in most RAPIDS libraries, including raft, cugraph, and ucxx. We also had to do a similar move of the files in the corresponding cudf PR. I have not taken the time to fully understand how pytest's rules for discovery have changed in pytest 8 or why they impact different libraries in subtly different ways, but they very clearly do based on what we've observed.

Overall, there must be a better way.

I would be happy if one could be found. However, in searching for one please note that cuml merging this PR is now a blocker for CI in other places. Since pytest 8 now requires a newer version of pytest-asyncio and pytest-asyncio made some breaking changes, the merge of the corresponding ucxx PR has made combined environments with both ucxx and cuml unsolvable, which blocks testing of RAPIDS in CCCL's CI, which hurts our ability to ensure that they don't merge breaking changes on us. One way or another we need to get the pin removed soon, so please account for that when deciding how to prioritize merging this PR.

@vyasr vyasr changed the title Remove pytest pin Reorganize tests and modify pytest invocation to support pytest 8 Jul 31, 2025
@bdice
Copy link
Contributor

bdice commented Jul 31, 2025

Yes - this is essentially the same types of changes (test reorganizations) that we've already made in other RAPIDS libraries. I support merging this soon, in order to unbreak our nightly CI and combined devcontainers and such.

Copy link
Contributor

@csadorf csadorf left a comment

Choose a reason for hiding this comment

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

I had a closer look at this and have come to the conclusion that cuML's pytest import mode should probably be append (or importlib), but not prepend, because we typically want to test the installed (and compiled) version rather than importing directly from source.

I've performed a small investigation by running pytest in prepend mode without any other tricks (like cd'ing into the cuml/tests/ directory) and found that pytest will, as one of its first actions during collection, try to import the cuml.benchmark.automated.dask.conftest module which is within a package. This causes pytest to walk up the path and try to import the cuml root module, which will eventually fail with

ERROR  - ModuleNotFoundError: No module named 'cuml.internals.logger'

because that is a Cython module.

Removing that conftest module, we run into the next problem: we are defining a number of pytest plugins within python/cuml/cuml/tests/conftest.py, which is not allowed as of pytest version 0.4.

The current hybrid approach of distributing our test modules within a cuml/tests/ directory, but not actually having a cuml.tests namespace, poses the worst of both worlds. We cannot utilize the ability to run tests via pyargs, but we run into a ton of problems when trying to invoke pytest from the root directory.

I have been hoping to address some of these quirks for quite some time and I believe that while somewhat rushed, the changes here pose an improvement. Hopefully we can then take the time and maybe revise our tests directory structure more holistically in a follow-up and either enable pytest --pyargs cuml or at least enable basic test execution from the repository root via pytest without the need for various wrapper scripts.

@csadorf csadorf removed the DO NOT MERGE Hold off on merging; see PR for details label Aug 1, 2025
@vyasr
Copy link
Contributor Author

vyasr commented Aug 1, 2025

/merge

@rapids-bot rapids-bot bot merged commit 6e73095 into rapidsai:branch-25.10 Aug 1, 2025
136 of 138 checks passed
@vyasr vyasr deleted the chore/remove_pytest_pin branch August 1, 2025 15:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci conda conda issue Cython / Python Cython or Python issue improvement Improvement / enhancement to an existing function non-breaking Non-breaking change

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants