Tests in test_genomics.py error instead of skipping when TensorFlow or simdna are missing
Bug
Three tests in deepchem/metrics/tests/test_genomics.py fail rather than skip when TensorFlow or simdna are not installed.
There are two separate causes.
test_in_silico_mutagenesis_shape and test_in_silico_mutagenesis_nonzero both call create_model_for_mutagenesis(), which uses tf.keras at line 54:
NameError: name 'tf' is not definedThe file imports tensorflow in a try/except at the top and sets has_tensorflow, but has_tensorflow is never used anywhere in the file. Both tests carry @pytest.mark.tensorflow, which selects them in CI but does not skip them when TensorFlow is absent.
test_get_motif_scores calls get_motif_scores(), which raises:
ImportError: This function requires simdna to be installed.There is no simdna guard in the test file at all.
test_get_pssm_scores passes, as it only uses numpy and scipy.
To Reproduce
- Install DeepChem from source on master (455d07f3e) with
pip install -e . - Do not install tensorflow or simdna
- Run
python -m pytest deepchem/metrics/tests/test_genomics.py
Result:
FAILED test_get_motif_scores
FAILED test_in_silico_mutagenesis_nonzero
FAILED test_in_silico_mutagenesis_shape
3 failed, 1 passedExpected behavior
Tests that need an optional dependency should be skipped when it is absent, not error. This is the same class of problem being fixed for the loader tests in #5051, in a file that PR does not cover.
Environment
- OS: macOS 26.6.2 (arm64)
- Python version: 3.12.13
- DeepChem version: 2.8.1.dev (editable install from master @ 455d07f3e)
- RDKit version (optional): 2026.3.6
- TensorFlow version (optional): not installed
- PyTorch version (optional): 2.14.0
- Any other relevant information: simdna not installed
Additional context
Related but not duplicates: #4745 change the bare except: in
this file to except Exception: as part of repo-wide sweeps, but none adds a skip
guard, so the tests still error. #3078 lists simdna among the optional dependencies
to trim guarding this test is a small step in that direction.
Happy to open a PR adding @unittest.skipIf guards for both dependencies.
Source: deepchem/deepchem