test_build.py 1.1 KB

1234567891011121314151617181920212223242526272829303132
  1. import os
  2. import textwrap
  3. import pytest
  4. from sklearn import __version__
  5. from sklearn.utils._openmp_helpers import _openmp_parallelism_enabled
  6. def test_openmp_parallelism_enabled():
  7. # Check that sklearn is built with OpenMP-based parallelism enabled.
  8. # This test can be skipped by setting the environment variable
  9. # ``SKLEARN_SKIP_OPENMP_TEST``.
  10. if os.getenv("SKLEARN_SKIP_OPENMP_TEST"):
  11. pytest.skip("test explicitly skipped (SKLEARN_SKIP_OPENMP_TEST)")
  12. base_url = "dev" if __version__.endswith(".dev0") else "stable"
  13. err_msg = textwrap.dedent("""
  14. This test fails because scikit-learn has been built without OpenMP.
  15. This is not recommended since some estimators will run in sequential
  16. mode instead of leveraging thread-based parallelism.
  17. You can find instructions to build scikit-learn with OpenMP at this
  18. address:
  19. https://scikit-learn.org/{}/developers/advanced_installation.html
  20. You can skip this test by setting the environment variable
  21. SKLEARN_SKIP_OPENMP_TEST to any value.
  22. """).format(base_url)
  23. assert _openmp_parallelism_enabled(), err_msg