kaxil opened a new pull request, #55915:
URL: https://github.com/apache/airflow/pull/55915

   Classes decorated with `@conf_vars` and other context managers were 
disappearing during pytest collection, causing tests to be silently skipped. 
This affected several test classes including `TestWorkerStart` in the Celery 
provider tests.
   
   Root cause: `ContextDecorator` transforms decorated classes into callable 
wrappers. Since pytest only collects actual type objects as test classes, these 
wrapped classes are ignored during collection.
   
   Simple reproduction (no Airflow needed):
   
   ```py
   import contextlib
   import inspect
   
   @contextlib.contextmanager
   def simple_cm():
       yield
   
   @simple_cm()
   class TestExample:
       def test_method(self):
           pass
   
   print(f'Is class? {inspect.isclass(TestExample)}')  # False - pytest won't 
collect
   ```
   
   and then run
   
   ```shell
   pytest test_example.py --collect-only
   ```
   
   Airflow reproduction:
   
   ```shell
   breeze run pytest 
providers/celery/tests/unit/celery/cli/test_celery_command.py --collect-only -v
   
   breeze run pytest 
providers/celery/tests/unit/celery/cli/test_celery_command.py --collect-only -v
   ```
   
   Solution:
   1. Fixed affected test files by replacing class-level `@conf_vars` 
decorators with pytest fixtures
   2. Created pytest fixtures to apply configuration changes
   3. Used `@pytest.mark.usefixtures` to apply configuration to test classes
   4. Added custom linter to prevent future occurrences and integrated it into 
pre-commit hooks
   
   Files changed:
   - Fixed 3 test files with problematic class decorators
   - Added custom linter with pre-commit integration
   
   This ensures pytest properly collects all test classes and prevents similar 
issues in the future through automated detection.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to