Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tests fail when mongomock is installed #420

Closed
mgorny opened this issue Nov 21, 2020 · 7 comments
Closed

Tests fail when mongomock is installed #420

mgorny opened this issue Nov 21, 2020 · 7 comments
Labels
type: bug Something isn't working

Comments

@mgorny
Copy link

mgorny commented Nov 21, 2020

When mongomock is installed in the environment, flask-mongoengine fails three tests:

==================================================================== FAILURES =====================================================================
____________________________ test_connection__should_parse_mongo_mock_uri__as_uri_and_as_settings[Dict format as URI] _____________________________

app = <Flask 'tests.conftest'>, config_extension = {'MONGODB_SETTINGS': {'HOST': 'mongomock://localhost:27017/flask_mongoengine_test_db'}}

    @pytest.mark.parametrize(
        ("config_extension"),
        [
            {
                "MONGODB_SETTINGS": {
                    "HOST": "mongomock://localhost:27017/flask_mongoengine_test_db"
                }
            },
            {
                "MONGODB_SETTINGS": {
                    "ALIAS": "simple_conn",
                    "HOST": "localhost",
                    "PORT": 27017,
                    "DB": "flask_mongoengine_test_db",
                    "IS_MOCK": True,
                }
            },
            {"MONGODB_HOST": "mongomock://localhost:27017/flask_mongoengine_test_db"},
        ],
        ids=("Dict format as URI", "Dict format as Param", "Config variable format as URI"),
    )
    def test_connection__should_parse_mongo_mock_uri__as_uri_and_as_settings(
        app, config_extension
    ):
        """Make sure a simple connection pass ALIAS setting variable."""
        db = MongoEngine()
        app.config.update(config_extension)
    
        # Verify no extension for Mongoengine yet created for app
        assert app.extensions == {}
        assert current_mongoengine_instance() is None
    
        # Create db connection. Should return None.
    
        with pytest.raises(RuntimeError) as error:
>           assert db.init_app(app) is None
E           Failed: DID NOT RAISE <class 'RuntimeError'>

tests/test_connection.py:167: Failed
___________________________ test_connection__should_parse_mongo_mock_uri__as_uri_and_as_settings[Dict format as Param] ____________________________

app = <Flask 'tests.conftest'>
config_extension = {'MONGODB_SETTINGS': {'ALIAS': 'simple_conn', 'DB': 'flask_mongoengine_test_db', 'HOST': 'localhost', 'IS_MOCK': True, ...}}

    @pytest.mark.parametrize(
        ("config_extension"),
        [
            {
                "MONGODB_SETTINGS": {
                    "HOST": "mongomock://localhost:27017/flask_mongoengine_test_db"
                }
            },
            {
                "MONGODB_SETTINGS": {
                    "ALIAS": "simple_conn",
                    "HOST": "localhost",
                    "PORT": 27017,
                    "DB": "flask_mongoengine_test_db",
                    "IS_MOCK": True,
                }
            },
            {"MONGODB_HOST": "mongomock://localhost:27017/flask_mongoengine_test_db"},
        ],
        ids=("Dict format as URI", "Dict format as Param", "Config variable format as URI"),
    )
    def test_connection__should_parse_mongo_mock_uri__as_uri_and_as_settings(
        app, config_extension
    ):
        """Make sure a simple connection pass ALIAS setting variable."""
        db = MongoEngine()
        app.config.update(config_extension)
    
        # Verify no extension for Mongoengine yet created for app
        assert app.extensions == {}
        assert current_mongoengine_instance() is None
    
        # Create db connection. Should return None.
    
        with pytest.raises(RuntimeError) as error:
>           assert db.init_app(app) is None
E           Failed: DID NOT RAISE <class 'RuntimeError'>

tests/test_connection.py:167: Failed
_______________________ test_connection__should_parse_mongo_mock_uri__as_uri_and_as_settings[Config variable format as URI] _______________________

app = <Flask 'tests.conftest'>, config_extension = {'MONGODB_HOST': 'mongomock://localhost:27017/flask_mongoengine_test_db'}

    @pytest.mark.parametrize(
        ("config_extension"),
        [
            {
                "MONGODB_SETTINGS": {
                    "HOST": "mongomock://localhost:27017/flask_mongoengine_test_db"
                }
            },
            {
                "MONGODB_SETTINGS": {
                    "ALIAS": "simple_conn",
                    "HOST": "localhost",
                    "PORT": 27017,
                    "DB": "flask_mongoengine_test_db",
                    "IS_MOCK": True,
                }
            },
            {"MONGODB_HOST": "mongomock://localhost:27017/flask_mongoengine_test_db"},
        ],
        ids=("Dict format as URI", "Dict format as Param", "Config variable format as URI"),
    )
    def test_connection__should_parse_mongo_mock_uri__as_uri_and_as_settings(
        app, config_extension
    ):
        """Make sure a simple connection pass ALIAS setting variable."""
        db = MongoEngine()
        app.config.update(config_extension)
    
        # Verify no extension for Mongoengine yet created for app
        assert app.extensions == {}
        assert current_mongoengine_instance() is None
    
        # Create db connection. Should return None.
    
        with pytest.raises(RuntimeError) as error:
>           assert db.init_app(app) is None
E           Failed: DID NOT RAISE <class 'RuntimeError'>

tests/test_connection.py:167: Failed
================================================================ warnings summary =================================================================
.tox/py36/lib64/python3.6/site-packages/_pytest/config/__init__.py:1230
  /tmp/flask-mongoengine/.tox/py36/lib64/python3.6/site-packages/_pytest/config/__init__.py:1230: PytestConfigWarning: Unknown config option: env_override_existing_values
  
    self._warn_or_fail_if_strict("Unknown config option: {}\n".format(key))

-- Docs: https://docs.pytest.org/en/stable/warnings.html
============================================================= short test summary info =============================================================
FAILED tests/test_connection.py::test_connection__should_parse_mongo_mock_uri__as_uri_and_as_settings[Dict format as URI] - Failed: DID NOT RAIS...
FAILED tests/test_connection.py::test_connection__should_parse_mongo_mock_uri__as_uri_and_as_settings[Dict format as Param] - Failed: DID NOT RA...
FAILED tests/test_connection.py::test_connection__should_parse_mongo_mock_uri__as_uri_and_as_settings[Config variable format as URI] - Failed: D...
===================================================== 3 failed, 42 passed, 1 warning in 4.16s =====================================================

@insspb
Copy link
Collaborator

insspb commented Nov 21, 2020

@mgorny Please specify flask-mongoengine version. New version just deployed to pip several hours ago, please test it.

@insspb insspb added stage: waiting-for-contributor Waiting for answer from original contributor. type: bug Something isn't working labels Nov 21, 2020
@mgorny
Copy link
Author

mgorny commented Nov 21, 2020

Reproduced with 0.9.5, 1.0.0 and git master (e090909).

You should be able to reproduce it easily by adding mongomock to tox env:

diff --git a/tox.ini b/tox.ini
index 7216f15..0569904 100644
--- a/tox.ini
+++ b/tox.ini
@@ -6,6 +6,7 @@ commands =
     python -m pytest {posargs}
 deps =
     PyMongo>3.9.0
+    mongomock
     pytest
     pytest-cov
 

@insspb
Copy link
Collaborator

insspb commented Dec 27, 2020

@mgorny Please take a look at #429, I think changes from there will help.

@mgorny
Copy link
Author

mgorny commented Dec 27, 2020

I've applied the changes from #429, and the tests still fail, with the same message.

@insspb
Copy link
Collaborator

insspb commented Dec 28, 2020

@mgorny thanks for info. I will try to find some time to look at mongomock, but no schedule promises

@insspb
Copy link
Collaborator

insspb commented Jul 8, 2022

@mgorny ok, since almost 2 years from issue I have some time to back to this project.
This issue now for sure fixed in my PR related to connection module and will be soon in master....

@insspb
Copy link
Collaborator

insspb commented Jul 8, 2022

@mgorny I made a special mark for mongomock related tests, as mentioned 3 tests had assertion that mongomock is not installed. So we will just skip them in systems, where mongomock installed. As our CI/CD work with real mongo, as well as our new nox configuration.

@insspb insspb removed the stage: waiting-for-contributor Waiting for answer from original contributor. label Jul 8, 2022
@insspb insspb closed this as completed in fb83fd6 Jul 8, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants