Skip to content

Skip TensorFlow-backed tests cleanly when the tf extra is absent - #3419

Open
natsukium wants to merge 1 commit into
DeepLabCut:mainfrom
natsukium:tests-skip-cleanly-without-tf-extra
Open

Skip TensorFlow-backed tests cleanly when the tf extra is absent#3419
natsukium wants to merge 1 commit into
DeepLabCut:mainfrom
natsukium:tests-skip-cleanly-without-tf-extra

Conversation

@natsukium

Copy link
Copy Markdown

While working on #3417, I noticed that the test suite could no longer be collected in a base install (without the tf extra).

pytest.importorskip("tensorflow") is meant to skip these tests when TensorFlow is not installed. However, in the affected modules the guard is placed after the imports of TF-backed code from deeplabcut.pose_estimation_tensorflow. During pytest's collection phase those imports run first, so a base install raises an import error before the guard is ever reached, making the importorskip effectively a no-op.

This PR does three things. It moves pytest.importorskip("tensorflow") above the TF-backed imports in the affected modules so they skip cleanly instead of erroring, it adds the missing guard to test_predict_supermodel.py which had none, and it marks the relocated imports with # noqa: E402 since they now intentionally follow module-level code.

These test modules call pytest.importorskip("tensorflow") only after
importing tensorflow-backed code (deeplabcut.pose_estimation_tensorflow).
Since a failing import aborts module loading, the guard was never reached.

Move importorskip above those imports so the modules skip cleanly, and add
the missing guard to test_predict_supermodel, which had none. This lets the
test suite be collected and run in a base install.

@deruyter92 deruyter92 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good PR, correct fix. LGTM!

@deruyter92
deruyter92 requested review from AlexEMG and MMathisLab July 28, 2026 18:07
@deruyter92 deruyter92 added the dependencies Pull requests that update a dependency file label Jul 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

dependencies Pull requests that update a dependency file

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants