BeanieODM / beanie

Asynchronous Python ODM for MongoDB
http://beanie-odm.dev/
Apache License 2.0
1.9k stars 201 forks source link

[HELP] pytest CollectionWasNotInitialized #307

Closed hd10180 closed 1 year ago

hd10180 commented 1 year ago

i clone the code, then run pytest or run poetry run pytest. it show lots of CollectionWasNotInitialized

_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

cls = <class 'tests.odm.models.DocumentTestModel'>

    @classmethod
    def get_settings(cls) -> DocumentSettings:
        """
        Get document settings, which was created on
        the initialization step

        :return: DocumentSettings class
        """
        if cls._document_settings is None:
>           raise CollectionWasNotInitialized
E           beanie.exceptions.CollectionWasNotInitialized

beanie/odm/documents.py:779: CollectionWasNotInitialized
______________________ ERROR at setup of test_save _______________________

    @pytest.fixture
    def document_not_inserted():
>       return DocumentTestModel(
            test_int=42,
            test_list=[SubDocument(test_str="foo"), SubDocument(test_str="bar")],
            test_doc=SubDocument(test_str="foobar"),
            test_str="kipasa",
        )

tests/odm/conftest.py:186: 

it seems like the init_beanie doesn't call or what i did wrong?@roman-right
anybody can help? by the way, i just want to know how to test the code using pytest and beanie

thanks for all.

hd10180 commented 1 year ago

finally, after long time googling, i add an pytest.ini file in the root dir

[pytest]
asyncio_mode=auto

and then i replace all the loop into event_loop, run pytest i got the 279 passed, 2 skipped, 1018 warnings in 76.82s (0:01:16)

maybe not the right way but it seems work.