Thanks to visit codestin.com
Credit goes to github.com

Skip to content

CLN avoid nested conftests #27954

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

Merged
merged 4 commits into from
Dec 13, 2023

Conversation

Charlie-XIAO
Copy link
Contributor

Reference Issues/PRs

Fixes #27806.

What does this implement/fix? Explain your changes.

The purpose is to avoid nested conftests which seems to cause problem on some specific platforms with pytest>7.0.1. See #27806 for discussion.

This PR combines all conftest.py under sklearn/ into a single one under the root directory (the originally empty conftest.py). Did not take care of the one under doc/ because I'm not sure what to do with it.

On my local machine, pytest, pytest sklearn, pytest sklearn/utils/tests, etc. raise errors with the main branch but work fine with this PR. I've checked that the number of collected tests is the same as before.

@lesteve Would you please take a look?

@Charlie-XIAO Charlie-XIAO changed the title No nested conftest TST avoid nested conftests Dec 13, 2023
@Charlie-XIAO Charlie-XIAO changed the title TST avoid nested conftests CLN avoid nested conftests Dec 13, 2023
Copy link

github-actions bot commented Dec 13, 2023

✔️ Linting Passed

All linting checks passed. Your pull request is in excellent shape! ☀️

Generated for commit: 3fcfa65. Link to the linter CI: here

Copy link
Member

@lesteve lesteve left a comment

Choose a reason for hiding this comment

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

Thanks for taking the time to do a PR!

I didn't think of it at the time, but could you try on your machine to only remove the root conftest.py and see whether it gets rid of the original issue on your machine? If so this may actually be the cleanest fix.

If only removing the root conftest.py does not fix it, and as mentioned in #27806 (comment), I would keep sklearn/conftest.py and move the content of sklearn/utils/tests/conftest.py to it.

Additional comments:

  • don't move the content to conftest.py. sklearn/conftest.py is used on purpose so that the conftest.py is inside the distributed package (e.g. on PyPI)
  • keep sklearn/externals/conftest.py this is less likely to cause issue since this gets ignored
  • on top of this, I am pretty sure you can remove the root conftest.py these days, this is more of an historical thing

@Charlie-XIAO
Copy link
Contributor Author

Charlie-XIAO commented Dec 13, 2023

I didn't think of it at the time, but could you try on your machine to only remove the root conftest.py and see whether it gets rid of the original issue on your machine? If so this may actually be the cleanest fix.

This doesn't seem to work.

keep sklearn/externals/conftest.py this is less likely to cause issue since this gets ignored

You're right keeping this file doesn't cause issue.

If only removing the root conftest.py does not fix it, and as mentioned in #27806 (comment), I would keep sklearn/conftest.py and move the content of sklearn/utils/tests/conftest.py to it.

@lesteve The strange thing is that, if I keep sklearn/conftest.py (current), no matter if I remove the root conftest.py or not, I get the assert mod not in mods error either when doing pytest or pytest sklearn, though indeed pytest sklearn/utils/tests does not raise. However, if I move sklearn/conftest.py to the root, both pytest or pytest sklearn work well.

@lesteve
Copy link
Member

lesteve commented Dec 13, 2023

Hmmm OK so you are saying pytest sklearn is not working on your machine as soon as sklearn/conftest.py exist. We can not really get rid of sklearn/conftest.py as it is useful to distributed with our package.

So contrary to what I thought, it seems like moving as much content to sklearn/conftest.py is not enough for it to work on your machine. I would recommend using python -m pytest sklearn in the mean time on your machine. Full disclosure (for other reasons than your issue), on my machine I have pytest aliased to python -m pytest and I don't remember seeing an issue because of this.

In an ideal world, someone would put together a simple reproducer for pytest-dev/pytest#9765. To be fair, it seems like it is not a single issue, since some people can reproduce on Windows, some people can reproduce on Linux. In our case, it seems Windows-specific.

@Charlie-XIAO
Copy link
Contributor Author

@lesteve Thanks for your response! Yet I think the current PR is okay for me. I in fact never really runs the whole test suite, but only run single module or file, so at least this PR solves my problem. In the corner cases I will use python -m pytest.

These said, should me close or keep this PR?

@lesteve
Copy link
Member

lesteve commented Dec 13, 2023

I am fine with this if this makes your like a bit easier:

  • the root conftest.py is not needed, it is there for historical reason, mostly to add the current directory to PYTHONPATH so that you can do pytest sklearn without installing with pip install -e (full disclosure this is what I am doing ...). Because we use a plugin for random seed, this is not enough these days and you need to do python -m pytest.
  • moving sklearn/utils/tests/conftest.py to sklearn/conftest.py is not too big a change

@thomasjpfan thomasjpfan merged commit 4d353c6 into scikit-learn:main Dec 13, 2023
@Charlie-XIAO Charlie-XIAO deleted the no-nested-conftest branch December 14, 2023 02:25
glemaitre pushed a commit to glemaitre/scikit-learn that referenced this pull request Feb 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

BUG: pytest error when loading conftest (seemingly platform-specific)
3 participants