fix: guard tensorflow import to allow test_nn collection without TF#104
Open
bugparty wants to merge 1 commit into
Open
fix: guard tensorflow import to allow test_nn collection without TF#104bugparty wants to merge 1 commit into
bugparty wants to merge 1 commit into
Conversation
Guard the `import tensorflow as tf` in nn_torch_models.py with a try/except so the module can be imported when tensorflow is not installed. Wrap all TF-dependent code (WGAN_GP_tf, TFNCELoss, and their helper functions) under `if tf is not None:`. Add `@pytest.mark.skipif` decorators to test_NCELoss and test_WGAN_GP in test_nn.py so they are skipped when tensorflow is unavailable, while PyTorch-only tests can still be collected and run. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
import tensorflow as tfinnumpy_ml/tests/nn_torch_models.pywithtry/except ImportErrorso the module can be imported when tensorflow is not installedWGAN_GP_tf,TFNCELoss, and helper functionsparam,params_with_name,ReLULayer,LinearLayer,Generator,Discriminator) underif tf is not None:@pytest.mark.skipif("tensorflow" not in sys.modules, reason="tensorflow not installed")totest_NCELossandtest_WGAN_GPintest_nn.pytest_nn.pyare now conditional ontensorflowbeing insys.modulesTest plan
test_nn.pycollects all 41 tests without tensorflow installedtest_NCELossandtest_WGAN_GPare properly skipped (reason: "tensorflow not installed")test_sigmoid_activation) still passTFNCELossandWGAN_GP_tfare not importable when TF is missing🤖 Generated with Claude Code