Skip to content

Fix test suite: resolve 7 failures from dependency updates#821

Open
yanjunqiAz wants to merge 3 commits intoQData:masterfrom
yanjunqiAz:fix/test-suite-compatibility
Open

Fix test suite: resolve 7 failures from dependency updates#821
yanjunqiAz wants to merge 3 commits intoQData:masterfrom
yanjunqiAz:fix/test-suite-compatibility

Conversation

@yanjunqiAz
Copy link
Copy Markdown
Collaborator

@yanjunqiAz yanjunqiAz commented Apr 16, 2026

Summary

  • Fix 2 code bugs caused by breaking changes in newer versions of transformers and gensim
  • Fix ChineseWordSwapMaskedLM using wrong tokenizer class and hardcoded CUDA
  • Update stale test expected output and add skip markers for optional dependencies
  • Fix CI workflows failing due to visdom build error

Details

Code fixes

textattack/trainer.pytransformers.optimization.AdamW was removed in transformers>=4.x. Replaced with torch.optim.AdamW, which is the recommended substitute.

textattack/transformations/word_swaps/chn_transformations/chinese_word_swap_masked.py:

  • BertTokenizer/BertForMaskedLM cannot load xlm-roberta-base (wrong tokenizer architecture). Switched to AutoTokenizer/AutoModelForMaskedLM which correctly auto-detect the model type.
  • Replaced hardcoded "cuda" device with auto-detection (torch.cuda.is_available()), so the transformation works on CPU-only machines.

Test fixes

tests/sample_outputs/list_augmentation_recipes.txt — Added missing BackTranscriptionAugmenter entry that was added to the codebase but not reflected in expected test output.

tests/test_word_embedding.py — Replaced deprecated gensim.models.keyedvectors.Word2VecKeyedVectors (removed in gensim 4.x) with gensim.models.KeyedVectors. Added skipif for when gensim is not installed.

tests/test_command_line/test_attack.py, tests/test_command_line/test_train.py — Added skip markers for tests that require tensorflow_hub (an optional dependency): interactive_mode, attack_from_transformers_adv_metrics, run_attack_hotflip_lstm_mr_4_adv_metrics, and test_train_tiny.

CI fix

.github/workflows/check-formatting.yml, .github/workflows/run-pytest.yml — Changed pip install -e .[dev] to pip install -e .[test]. The [dev] extras include visdom (via [optional]), which fails to build in pip's isolated build environments because its setup.py imports pkg_resources from setuptools. The formatting and test workflows only need [test] extras.

Test plan

  • Full test suite: 68 passed, 5 skipped (optional deps), 0 failed
  • Verified gensim.models.KeyedVectors.load_word2vec_format works with gensim 4.x
  • CI checks passing after workflow fix

Code fixes:
- Replace removed transformers.optimization.AdamW with torch.optim.AdamW
  in trainer.py (removed in transformers>=4.x)
- Use AutoTokenizer/AutoModelForMaskedLM instead of BertTokenizer/BertForMaskedLM
  in ChineseWordSwapMaskedLM, since xlm-roberta-base requires its own tokenizer
- Fix hardcoded CUDA device in ChineseWordSwapMaskedLM to auto-detect device

Test fixes:
- Update stale expected output for list_augmentation_recipes to include
  BackTranscriptionAugmenter
- Add pytest.skip for tests requiring tensorflow_hub when not installed
  (interactive_mode, adv_metrics attack tests, train test)
- Add pytest.skipif for test_embedding_gensim when gensim not installed
- Replace deprecated gensim Word2VecKeyedVectors API with KeyedVectors
The [dev] extras include visdom (via [optional]), which fails to build
in pip's isolated build environments because visdom's setup.py imports
pkg_resources from setuptools, which is not available in isolated builds
with newer pip versions.

The formatting workflow only needs linting tools and the pytest workflow
only needs test tools, so [test] extras are sufficient for both.
@yanjunqiAz yanjunqiAz mentioned this pull request Apr 16, 2026
2 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant