kerrickstaley / genanki

A Python 3 library for generating Anki decks
MIT License
1.99k stars 150 forks source link

pytest: Correct fatal error: AttributeError: module 'anki' has no attribute 'Collection'. Did you mean: 'collection'? #144

Open dvklopfenstein opened 1 week ago

dvklopfenstein commented 1 week ago

Hello,

Thank you for this wonderful package. I am looking forward to using it.

I forked and cloned the genanki repo and ran $ pytest All tests in tests/test_genanki.py failed with this error:

… AttributeError: module 'anki' has no attribute 'Collection'. Did you mean: 'collection'?

Here is the pytest summary:

collected 58 items

tests/test_builtin_models.py ..                                                                                                                                                    [  3%]
tests/test_cloze.py ....                                                                                                                                                           [ 10%]
tests/test_genanki.py EEEEEEEEEEEEEEEEEEEEEE                                                                                                                                       [ 48%]
tests/test_note.py ..............................          

To fix this, I changed accessing anki.Collection to anki.collection.Collection, which removed the Collection error.

Many tests in tests/test_genanki.py now pass and there are no longer errors regardingCollection.

If this fixes the Collection error, please consider accepting this PR.

Thank you again for wonderful package.

@dvklopfenstein, PhD

PS: FYI: Some tests now fail with a new error, but I believe it is out-of-scope for this PR:

AttributeError: 'NoneType' object has no attribute 'strip_html'

Here is the pytest summary:

collected 58 items

tests/test_builtin_models.py ..                                                                                                                                                    [  3%]
tests/test_cloze.py ....                                                                                                                                                           [ 10%]
tests/test_genanki.py FFFF......FFF..FFFFFFF                                                                                                                                       [ 48%]
tests/test_note.py ..............................   
dvklopfenstein commented 1 week ago

FYI: Below is what I see when running:

$ python3 -m pytest tests -vv -cov genanki

The results match the summary shown on https://github.com/kerrickstaley/genanki/pull/144#issue-2534795533

collected 58 items

tests/test_builtin_models.py::test_builtin_models PASSED                                                                                                                                                                                                          [  1%]
tests/test_builtin_models.py::test_cloze_with_single_field_warns PASSED                                                                                                                                                                                           [  3%]
tests/test_cloze.py::test_cloze PASSED                                                                                                                                                                                                                            [  5%]
tests/test_cloze.py::test_cloze_multi_field PASSED                                                                                                                                                                                                                [  6%]
tests/test_cloze.py::test_cloze_indicies_do_not_start_at_1 PASSED                                                                                                                                                                                                 [  8%]
tests/test_cloze.py::test_cloze_newlines_in_deletion PASSED                                                                                                                                                                                                       [ 10%]
tests/test_genanki.py::TestWithCollection::test_generated_deck_can_be_imported FAILED                                                                                                                                                                             [ 12%]
tests/test_genanki.py::TestWithCollection::test_generated_deck_has_valid_cards FAILED                                                                                                                                                                             [ 13%]
tests/test_genanki.py::TestWithCollection::test_multi_deck_package FAILED                                                                                                                                                                                         [ 15%]
tests/test_genanki.py::TestWithCollection::test_card_isEmpty__with_2_fields__succeeds FAILED                                                                                                                                                                      [ 17%]
tests/test_genanki.py::TestWithCollection::test_Model_req PASSED                                                                                                                                                                                                  [ 18%]
tests/test_genanki.py::TestWithCollection::test_Model_req__cn PASSED                                                                                                                                                                                              [ 20%]
tests/test_genanki.py::TestWithCollection::test_Model_req__with_hint PASSED                                                                                                                                                                                       [ 22%]
tests/test_genanki.py::TestWithCollection::test_notes_generate_cards_based_on_req__cn PASSED                                                                                                                                                                      [ 24%]
tests/test_genanki.py::TestWithCollection::test_notes_generate_cards_based_on_req__with_hint PASSED                                                                                                                                                               [ 25%]
tests/test_genanki.py::TestWithCollection::test_Note_with_guid_property PASSED                                                                                                                                                                                    [ 27%]
tests/test_genanki.py::TestWithCollection::test_media_files FAILED                                                                                                                                                                                                [ 29%]
tests/test_genanki.py::TestWithCollection::test_media_files_in_subdirs FAILED                                                                                                                                                                                     [ 31%]
tests/test_genanki.py::TestWithCollection::test_media_files_absolute_paths FAILED                                                                                                                                                                                 [ 32%]
tests/test_genanki.py::TestWithCollection::test_write_deck_without_deck_id_fails PASSED                                                                                                                                                                           [ 34%]
tests/test_genanki.py::TestWithCollection::test_write_deck_without_name_fails PASSED                                                                                                                                                                              [ 36%]
tests/test_genanki.py::TestWithCollection::test_card_suspend FAILED                                                                                                                                                                                               [ 37%]
tests/test_genanki.py::TestWithCollection::test_deck_with_description FAILED                                                                                                                                                                                      [ 39%]
tests/test_genanki.py::TestWithCollection::test_card_added_date_is_recent FAILED                                                                                                                                                                                  [ 41%]
tests/test_genanki.py::TestWithCollection::test_model_with_latex_pre_and_post FAILED                                                                                                                                                                              [ 43%]
tests/test_genanki.py::TestWithCollection::test_model_with_sort_field_index FAILED                                                                                                                                                                                [ 44%]
tests/test_genanki.py::TestWithCollection::test_notes_with_due1 FAILED                                                                                                                                                                                            [ 46%]
tests/test_genanki.py::TestWithCollection::test_notes_with_due2 FAILED                                                                                                                                                                                            [ 48%]
tests/test_note.py::test_ok PASSED                                                                                                                                                                                                                                [ 50%]
tests/test_note.py::TestTags::test_init PASSED                                                                                                                                                                                                                    [ 51%]
tests/test_note.py::TestTags::test_assign PASSED                                                                                                                                                                                                                  [ 53%]
tests/test_note.py::TestTags::test_assign_element PASSED                                                                                                                                                                                                          [ 55%]
tests/test_note.py::TestTags::test_assign_slice PASSED                                                                                                                                                                                                            [ 56%]
tests/test_note.py::TestTags::test_append PASSED                                                                                                                                                                                                                  [ 58%]
tests/test_note.py::TestTags::test_extend PASSED                                                                                                                                                                                                                  [ 60%]
tests/test_note.py::TestTags::test_insert PASSED                                                                                                                                                                                                                  [ 62%]
tests/test_note.py::test_num_fields_equals_model_ok PASSED                                                                                                                                                                                                        [ 63%]
tests/test_note.py::test_num_fields_less_than_model_raises PASSED                                                                                                                                                                                                 [ 65%]
tests/test_note.py::test_num_fields_more_than_model_raises PASSED                                                                                                                                                                                                 [ 67%]
tests/test_note.py::TestFindInvalidHtmlTagsInField::test_ok PASSED                                                                                                                                                                                                [ 68%]
tests/test_note.py::TestFindInvalidHtmlTagsInField::test_ok_with_space PASSED                                                                                                                                                                                     [ 70%]
tests/test_note.py::TestFindInvalidHtmlTagsInField::test_ok_multiple PASSED                                                                                                                                                                                       [ 72%]
tests/test_note.py::TestFindInvalidHtmlTagsInField::test_ok_br PASSED                                                                                                                                                                                             [ 74%]
tests/test_note.py::TestFindInvalidHtmlTagsInField::test_ok_br2 PASSED                                                                                                                                                                                            [ 75%]
tests/test_note.py::TestFindInvalidHtmlTagsInField::test_ok_br3 PASSED                                                                                                                                                                                            [ 77%]
tests/test_note.py::TestFindInvalidHtmlTagsInField::test_ok_attrs PASSED                                                                                                                                                                                          [ 79%]
tests/test_note.py::TestFindInvalidHtmlTagsInField::test_ok_uppercase PASSED                                                                                                                                                                                      [ 81%]
tests/test_note.py::TestFindInvalidHtmlTagsInField::test_ng_empty PASSED                                                                                                                                                                                          [ 82%]
tests/test_note.py::TestFindInvalidHtmlTagsInField::test_ng_empty_space PASSED                                                                                                                                                                                    [ 84%]
tests/test_note.py::TestFindInvalidHtmlTagsInField::test_ng_invalid_characters PASSED                                                                                                                                                                             [ 86%]
tests/test_note.py::TestFindInvalidHtmlTagsInField::test_ng_invalid_characters_end PASSED                                                                                                                                                                         [ 87%]
tests/test_note.py::TestFindInvalidHtmlTagsInField::test_ng_issue_28 PASSED                                                                                                                                                                                       [ 89%]
tests/test_note.py::TestFindInvalidHtmlTagsInField::test_ok_html_comment PASSED                                                                                                                                                                                   [ 91%]
tests/test_note.py::TestFindInvalidHtmlTagsInField::test_ok_cdata PASSED                                                                                                                                                                                          [ 93%]
tests/test_note.py::test_warns_on_invalid_html_tags PASSED                                                                                                                                                                                                        [ 94%]
tests/test_note.py::test_suppress_warnings PASSED                                                                                                                                                                                                                 [ 96%]
tests/test_note.py::test_does_not_warn_on_html_tags_in_guid PASSED                                                                                                                                                                                                [ 98%]
tests/test_note.py::test_furigana_field PASSED                                                                                                                                                                                                                    [100%]