The Wayback Machine - https://web.archive.org/web/20210118131342/https://github.com/rapidsai/cuml/issues/3093
Skip to content
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

[FEA] Improve Pytest Organization and Configuration #3093

Open
mdemoret-nv opened this issue Oct 30, 2020 · 2 comments
Open

[FEA] Improve Pytest Organization and Configuration #3093

mdemoret-nv opened this issue Oct 30, 2020 · 2 comments

Comments

@mdemoret-nv
Copy link
Contributor

@mdemoret-nv mdemoret-nv commented Oct 30, 2020

Our current organization of pytest configuration files is not optimal for locally running tests and could be improved to add flexibility and increase utility for both local and CI runs. Most of what follows are my personal issue with the current setup and ideas for how it could be improved. I would love to have a discussion on this topic and incorporate feedback from the team.

For some context, I first started looking at this when trying to use the --run_stress commands locally and ran into issues:

~/Repos/rapids/cuml-dev2/python$ pytest --run_stress
ERROR: usage: pytest [options] [file_or_dir] [file_or_dir] [...]
pytest: error: unrecognized arguments: --run_stress
  inifile: /home/mdemoret/Repos/rapids/cuml-dev2/python/pytest.ini
  rootdir: /home/mdemoret/Repos/rapids/cuml-dev2/python

The way we currently have our repo organized is not recommended by pytest. They suggest moving the conftest.py folder to the root of the python package or to create plugins since conftest.py deeper in directories are not scanned initially. Given the growing nature of our current conftest.py, growing number of tests, and need to adjust which tests are run, I think it makes sense to make the following changes:

  1. Move all command line options added in pytest_addoption to plugins in python/cuml/test/plugins
  2. Require the necessary plugins using the addopts section in pytest.ini (i.e. addopts = -p "cuml.test.plugins.custom_options_plugin")
    1. And in general, make better use of pytest.ini and rely less on command line arguments in ci/gpu/build.sh
  3. Change the --import-mode to --import-mode=importlib
    1. This is necessary to make addopts = -p "cuml.test.plugins.custom_options_plugin" work and will become the default. This also makes it easier during development since both local and pip installed packages can be resolved.
  4. Move optional functionality in conftest.py to new plugins
    1. For example, the bad_cuml_array_check could be a plugin which would make it disable-able
  5. Increase our use of markers.
    1. Markers are a great way to pick and choose which tests to skip or focus on. We don't use them enough

Making these changes will allow us more flexibility when running pytest locally and in CI. I have already tested some of these out and they work well. For example, I added a memory checker plugin here, and also added a "quick_run" plugin here which reduces the number of parameters run for each test (overall reduction from 34267 test to 2184).

Would be interested to hear everyone else's thoughts on the matter

@mdemoret-nv
Copy link
Contributor Author

@mdemoret-nv mdemoret-nv commented Nov 2, 2020

After further experimentation, I think using the addopts = -p "cuml.test.plugins.custom_options_plugin" value in pytest.ini might not be the best way to set this up. The major downside of doing it this way is this causes cuml to be imported very early in the pytest lifecycle. This is only a problem for code coverage since most of the cuml/**/__init__.py files will be marked as missed since they have already been imported. This could be worked around by either:

  1. Moving the plugins outside of the python/cuml folder.
    1. Prevents the library cuml from being imported, but may cause other issues
  2. Keeping the organization mentioned above, but adding */__init__py to the ignore list
    1. Not sure how much value there is in testing coverage of these files anyways
  3. Adding a conftest.py in ./python that imports the necessary plugins
    1. Only downside of doing this is cluttering our root python folder
@mdemoret-nv
Copy link
Contributor Author

@mdemoret-nv mdemoret-nv commented Nov 2, 2020

Regarding the "quick_run" plugin I mentioned above, I have done a quick codecov comparison to see how much coverage we lose for the improved testing time. Preliminary results (all run locally with a recent 0.17 branch):

Running full tests:

  • 20749/34030 tests run
  • 3717 line misses
  • Total coverage: 58.60%
  • Total runtime: 1232.56 s

Running with --quick_run:

  • 1922/34030 tests run
  • 3764 line misses
  • Total coverage: 58.07%
  • Total runtime: 344.17 s

So for roughly ~75% reduction in runtime, you can hit 99.1% of the same lines. Would be helpful when running locally before doing a full test suite run.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Feature Planning
Needs prioritizing
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.