[fix] Resolve CI error due to import error#256
Conversation
There was a problem hiding this comment.
Code Review
This pull request resolves a CI error that occurs during pytest collection by moving an import with an optional dependency into a test function. The change is effective and correctly solves the problem. I have provided one suggestion to use pytest.importorskip as a more idiomatic alternative for handling optional dependencies in tests, which could improve the maintainability of the code.
| } | ||
| ) | ||
|
|
||
| from integrations.verifiers.verifiers_generator import VerifiersGenerator |
There was a problem hiding this comment.
While this local import solves the ImportError during test collection, a more idiomatic pytest approach is to use pytest.importorskip() at the top of the test module. This would allow you to keep the VerifiersGenerator import at the top level, and it would clearly mark all tests in this file to be skipped if the verifiers package isn't installed. This is often cleaner and more maintainable for test files that depend on optional integrations.
For example, you could add the following at the top of the file and remove this local import:
import pytest
pytest.importorskip("verifiers")
from integrations.verifiers.verifiers_generator import VerifiersGeneratorThere was a problem hiding this comment.
Hm, that might be true but I also don't want tests to be silently skipped
We cannot import `VerifiersGenerator` unless `--with verifiers` is included in the `uv` command. An error is thrown when pytest is collecting all tests and tries to import `VerifiersGenerator`. This PR moves the import of `VerifiersGenerator` in the test into the test body so that it's only imported when executed. Confirmed that Verifiers integration tests still pass with the commands in the CI pipeline.
We cannot import
VerifiersGeneratorunless--with verifiersis included in theuvcommand. An error is thrown when pytest is collecting all tests and tries to importVerifiersGenerator.This PR moves the import of
VerifiersGeneratorin the test into the test body so that it's only imported when executed.Confirmed that Verifiers integration tests still pass with the commands in the CI pipeline: