Skip to content

Celery tests require package; test blows up if Celery not installed instead of skipping the tests gracefully #750

Description

@ngie-eign

Summary

Expected vs actual result

Expected

Tests should be skipped if Celery isn't installed.

Actual

Tests blow up with an ImportError similar to what's provided at the bottom of the report.

Reproducer

Attempt to run tests on host without Celery installed.

Versions

% python3 -V; uname -sr
Python 3.12.13
FreeBSD 15.1-RELEASE-p1

Version being tested/installed is vanilla 7.1.0.

Config

n/a

Code

% cd devel/py-pytest-cov
% sudo make test
...

<...>/freebsd-ports/devel/py-pytest-cov/work-py312/pytest_cov-7.1.0/tests/test_pytest_cov.py:771: Failed
------------------------------------------------------------------------------------------------------------ Captured stdout call -------------------------------------------------------------------------------------------------------------
running: /usr/local/bin/python3.12 -mpytest --basetemp=/tmp/pytest-of-root/pytest-0/test_celery0/runpytest-0 -vv -s --cov --cov-report=term-missing small_celery.py --basetemp=/tmp/pytest-of-root/pytest-0/basetemp
     in: /tmp/pytest-of-root/pytest-0/test_celery0
============================= test session starts ==============================
platform freebsd15 -- Python 3.12.13, pytest-8.4.2, pluggy-1.6.0 -- /usr/local/bin/python3.12
cachedir: .pytest_cache
hypothesis profile 'default'
rootdir: /tmp/pytest-of-root/pytest-0/test_celery0
configfile: pyproject.toml
plugins: hypothesis-6.155.7, cov-7.1.0, xdist-3.8.0, flaky-3.8.1
collecting ... collected 0 items / 1 error

==================================== ERRORS ====================================
_______________________ ERROR collecting small_celery.py _______________________
ImportError while importing test module '/tmp/pytest-of-root/pytest-0/test_celery0/small_celery.py'.
Hint: make sure your test modules/packages have valid Python names.
Traceback:
/usr/local/lib/python3.12/site-packages/_pytest/python.py:498: in importtestmodule
    mod = import_path(
/usr/local/lib/python3.12/site-packages/_pytest/pathlib.py:587: in import_path
    importlib.import_module(module_name)
/usr/local/lib/python3.12/importlib/__init__.py:90: in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
<frozen importlib._bootstrap>:1387: in _gcd_import
    ???
<frozen importlib._bootstrap>:1360: in _find_and_load
    ???
<frozen importlib._bootstrap>:1331: in _find_and_load_unlocked
    ???
<frozen importlib._bootstrap>:935: in _load_unlocked
    ???
/usr/local/lib/python3.12/site-packages/_pytest/assertion/rewrite.py:186: in exec_module
    exec(co, module.__dict__)
small_celery.py:3: in <module>
    from celery import Celery
E   ModuleNotFoundError: No module named 'celery'
=========================== short test summary info ============================
ERROR small_celery.py
!!!!!!!!!!!!!!!!!!!! Interrupted: 1 error during collection !!!!!!!!!!!!!!!!!!!!
=============================== 1 error in 0.48s ===============================

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions