Skip to content

MNT move pytest pluging list to root folder #22976

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 8 commits into from
Mar 30, 2022

Conversation

adrinjalali
Copy link
Member

Activating plugins in conftest.py located in a non-root location is deprecated, and pytest --collect-only fails on pytest=6.2.5. This PR moves the plugin activation to the root config file.

cc @ogrisel

$ pytest --collect-only                                             
============================================================================ test session starts ============================================================================
platform linux -- Python 3.10.2, pytest-6.2.5, py-1.11.0, pluggy-1.0.0
rootdir: /home/adrin/Projects/sklearn/scikit-learn, configfile: setup.cfg, testpaths: sklearn
plugins: xdist-2.5.0, typeguard-2.13.3, forked-1.4.0
collected 0 items / 1 error                                                                                                                                                 

================================================================================== ERRORS ===================================================================================
_______________________________________________________________________ ERROR collecting test session _______________________________________________________________________
Defining 'pytest_plugins' in a non-top-level conftest is no longer supported:
It affects the entire test suite instead of just below the conftest as expected.
  /home/adrin/Projects/sklearn/scikit-learn/sklearn/conftest.py
Please move it to a top level conftest file at the rootdir:
  /home/adrin/Projects/sklearn/scikit-learn
For more information, visit:
  https://docs.pytest.org/en/stable/deprecations.html#pytest-plugins-in-non-top-level-conftest-files
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Interrupted: 1 error during collection !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
=================================================================== no tests collected, 1 error in 0.13s ====================================================================

@thomasjpfan
Copy link
Member

I do not think this works with --pyargs + wheels, because the root conftest.py does not make it into the wheel. The alternative is to run pytest with the sklearn folder:

pytest --collect-only sklearn

@adrinjalali
Copy link
Member Author

"discovering tests" in VSCODE now fails because of this. What's the workaround there then?

@thomasjpfan
Copy link
Member

I tried a few ways to fix this, and it turns out --pyargs already does not work pytest-xdist + SKLEARN_TESTS_GLOBAL_RANDOM_SEED="any" when running in another directory.

I pushed a commit where pytest_plugins is removed all together and fixing the arm build (hopefully). This should also resolve the issue with vscode.

@adrinjalali
Copy link
Member Author

adrinjalali commented Mar 28, 2022

Then is this comment not valid?

 # This plugin is necessary to define the random seed fixture

@thomasjpfan
Copy link
Member

thomasjpfan commented Mar 28, 2022

There are two mechanisms for registering the plugin. One in setup.cfg:

scikit-learn/setup.cfg

Lines 13 to 16 in d14fd82

# Activate the plugin explicitly to ensure that the seed is reported
# correctly on the CI when running `pytest --pyargs sklearn` from the
# source folder.
-p sklearn.tests.random_seed

and one in conftest.py. Looking at the error from wheel building, it looks like we still need both of them.

@thomasjpfan
Copy link
Member

I pushed another commit with your original solution of moving pytest_plugins up a directory to see if the wheel build test works.

@adrinjalali
Copy link
Member Author

Thanks, you might wanna cancel Travis runs though :P

@adrinjalali
Copy link
Member Author

Nope, the wheels fail 🙄

Copy link
Member

@thomasjpfan thomasjpfan left a comment

Choose a reason for hiding this comment

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

This PR now works now.

I tested on my fork with SKLEARN_TESTS_GLOBAL_RANDOM_SEED="any" and SKLEARN_TESTS_GLOBAL_RANDOM_SEED is shown correctly in the logs.

@jeremiedbb
Copy link
Member

jeremiedbb commented Mar 30, 2022

@adrinjalali or @thomasjpfan do you confirm that it solves the discovering tests issue on vscode ?

@thomasjpfan
Copy link
Member

I can confirm that test collection works on VSCode.

Copy link
Member

@jeremiedbb jeremiedbb left a comment

Choose a reason for hiding this comment

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

LGTM

@jeremiedbb jeremiedbb merged commit 86c62cf into scikit-learn:main Mar 30, 2022
@adrinjalali adrinjalali deleted the conftest branch March 31, 2022 08:57
glemaitre pushed a commit to glemaitre/scikit-learn that referenced this pull request Apr 6, 2022
jjerphan pushed a commit to jjerphan/scikit-learn that referenced this pull request Apr 29, 2022
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