NatLibFi / Annif

Annif is a multi-algorithm automated subject indexing tool for libraries, archives and museums.
https://annif.org
Other
190 stars 41 forks source link

Imports isolation in tests #710

Open juhoinkinen opened 1 year ago

juhoinkinen commented 1 year ago

When working on PR #708, I accidentally removed this inline import:

https://github.com/NatLibFi/Annif/blob/fb512928b455f785f4799e0c6b96db5ecbfb12b3/annif/project.py#L205

This made annif index command fail:

...
File "/home/local/jmminkin/git/Annif/annif/cli.py", line 322, in run_index
    results = project.suggest_corpus(documents, backend_params).filter(limit, threshold)
  File "/home/local/jmminkin/git/Annif/annif/project.py", line 238, in suggest_corpus
    return annif.suggestion.SuggestionResults(suggestions)
AttributeError: module 'annif' has no attribute 'suggestion'

But this was not detected by tests for index command. Seems that some commands that are tested before import annif.suggestion, and this import remains for index command.

The tests should probably be some way more isolated to be able to detected this kind of possibility for bugs.

osma commented 1 year ago

I think that could be a consequence of running the CLI tests via CliRunner. It simulates a CLI execution environment, but isn't quite the same as running the commands separately from a real CLI. If we wanted to test that, we'd need something like a shell script (or possibly even a bats test suite) that runs the annif commands separately.