Skip to content

Only load the necesssary backends when testing with skip_backend or only_backend markers #2654

@ghisvail

Description

@ghisvail

Summary

I am currently packaging the scikit-hep stack for Guix, and I am facing troubles enabling the tests for the basic set of dependencies.

It looks like despite calling pytest with the only_numpy marker, it tries to load the other backends:

tests/conftest.py:63: in <module>
    (pyhf.tensor.pytorch_backend(), None),
     ^^^^^^^^^^^^^^^^^^^^^^^^^^^
/gnu/store/jabv9192g9pi22w6cn6zwf57ajk8jm80-python-pyhf-0.7.6/lib/python3.11/site-packages/pyhf/tensor/__init__.py:54: in __getattr__
    raise exceptions.ImportBackendError(
E   pyhf.exceptions.ImportBackendError: ('There was a problem importing PyTorch. The pytorch backend cannot be used.', ModuleNotFoundError("No module named 'torch'"))

I did a quick review of the code in conftest.py, and indeed the backend fixture calls pyhf.set_backend(...) for the whole parameter set, irrespective of whether they are excluded via skip_$backend or only_$backend.

It would be nice if such behaviour could be changed to only call pyhf.set_backend("numpy") if -m only_numpy is specified.

Cheers,

Additional Information

Code of Conduct

  • I agree to follow the Code of Conduct

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions