code: def test_invalid_by(self, by, doc_en):
      with pytest.raises((AttributeError, TypeError)):
          _ = extract.to_bag_of_terms(doc_en, by=by, ngs=2)
  
file_path: textacy/tests/extract/test_bags.py
imports: import pytest
  import spacy
  from textacy import extract
label_desc: Use image node_id 5 for calling the TestBagOfTerms obj's underlying member method code with example usage: obj.test_invalid_by(by, doc_en) without return types