Pytest -m connection fails with 4 errors

Here is my .ini file

# Ticket: Connection
# Rename this file to .ini after filling in your MFLIX_DB_URI and your SECRET_KEY
# Do not surround the URI with quotes

[PROD]
SECRET_KEY = super_secret_key_you_should_change
MFLIX_DB_URI = mongodb+srv://m220student:m220password@mflix.0hvvg.mongodb.net/test
MFLIX_NS = sample_mflix

[TEST]
SECRET_KEY = super_secret_testing_key
MFLIX_DB_URI = MFLIX_DB_URI = mongodb+srv://m220student:m220password@mflix.0hvvg.mongodb.net/test
MFLIX_NS = sample_mflix

Here is the errors when running pytest -m connection

(mflix) C:\Users\meirv\mflix-python>pytest -m connection
============================= test session starts =============================
platform win32 -- Python 3.9.5, pytest-3.3.0, py-1.8.0, pluggy-0.6.0
rootdir: C:\Users\meirv\mflix-python, inifile: pytest.ini
plugins: flask-0.11.0
collected 43 items

tests\test_db_connection.py EEEE                                         [100%]

=================================== ERRORS ====================================
_____________________ ERROR at setup of test_atlas_setup ______________________

request = <SubRequest '_configure_application' for <Function 'test_atlas_setup'>>
monkeypatch = <_pytest.monkeypatch.MonkeyPatch object at 0x000002064B10C7F0>

    @pytest.fixture(autouse=True)
    def _configure_application(request, monkeypatch):
        """Use `pytest.mark.options` decorator to pass options to your application
        factory::

            @pytest.mark.options(debug=False)
            def test_something(app):
                assert not app.debug, 'the application works not in debug mode!'

        """
        if 'app' not in request.fixturenames:
            return

>       app = getfixturevalue(request, 'app')

..\anaconda3\envs\mflix\lib\site-packages\pytest_flask\plugin.py:110:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
..\anaconda3\envs\mflix\lib\site-packages\pytest_flask\pytest_compat.py:3: in getfixturevalue
    return request.getfixturevalue(value)
tests\conftest.py:14: in app
    app.config['SECRET_KEY'] = config['TEST']['SECRET_KEY']
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

self = <configparser.ConfigParser object at 0x000002064A3918B0>, key = 'TEST'

    def __getitem__(self, key):
        if key != self.default_section and not self.has_section(key):
>           raise KeyError(key)
E           KeyError: 'TEST'

..\anaconda3\envs\mflix\lib\configparser.py:960: KeyError
_____________________ ERROR at setup of test_basic_movies _____________________

request = <SubRequest '_configure_application' for <Function 'test_basic_movies'>>
monkeypatch = <_pytest.monkeypatch.MonkeyPatch object at 0x000002064B13EE20>

    @pytest.fixture(autouse=True)
    def _configure_application(request, monkeypatch):
        """Use `pytest.mark.options` decorator to pass options to your application
        factory::

            @pytest.mark.options(debug=False)
            def test_something(app):
                assert not app.debug, 'the application works not in debug mode!'

        """
        if 'app' not in request.fixturenames:
            return

>       app = getfixturevalue(request, 'app')

..\anaconda3\envs\mflix\lib\site-packages\pytest_flask\plugin.py:110:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
..\anaconda3\envs\mflix\lib\site-packages\pytest_flask\pytest_compat.py:3: in getfixturevalue
    return request.getfixturevalue(value)
tests\conftest.py:14: in app
    app.config['SECRET_KEY'] = config['TEST']['SECRET_KEY']
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

self = <configparser.ConfigParser object at 0x000002064A3918B0>, key = 'TEST'

    def __getitem__(self, key):
        if key != self.default_section and not self.has_section(key):
>           raise KeyError(key)
E           KeyError: 'TEST'

..\anaconda3\envs\mflix\lib\configparser.py:960: KeyError
__________________ ERROR at setup of test_search_by_movie_id __________________

request = <SubRequest '_configure_application' for <Function 'test_search_by_movie_id'>>
monkeypatch = <_pytest.monkeypatch.MonkeyPatch object at 0x000002064B1843A0>

    @pytest.fixture(autouse=True)
    def _configure_application(request, monkeypatch):
        """Use `pytest.mark.options` decorator to pass options to your application
        factory::

            @pytest.mark.options(debug=False)
            def test_something(app):
                assert not app.debug, 'the application works not in debug mode!'

        """
        if 'app' not in request.fixturenames:
            return

>       app = getfixturevalue(request, 'app')

..\anaconda3\envs\mflix\lib\site-packages\pytest_flask\plugin.py:110:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
..\anaconda3\envs\mflix\lib\site-packages\pytest_flask\pytest_compat.py:3: in getfixturevalue
    return request.getfixturevalue(value)
tests\conftest.py:14: in app
    app.config['SECRET_KEY'] = config['TEST']['SECRET_KEY']
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

self = <configparser.ConfigParser object at 0x000002064A3918B0>, key = 'TEST'

    def __getitem__(self, key):
        if key != self.default_section and not self.has_section(key):
>           raise KeyError(key)
E           KeyError: 'TEST'

..\anaconda3\envs\mflix\lib\configparser.py:960: KeyError
__________________ ERROR at setup of test_simple_text_search __________________

request = <SubRequest '_configure_application' for <Function 'test_simple_text_search'>>
monkeypatch = <_pytest.monkeypatch.MonkeyPatch object at 0x000002064B208FD0>

    @pytest.fixture(autouse=True)
    def _configure_application(request, monkeypatch):
        """Use `pytest.mark.options` decorator to pass options to your application
        factory::

            @pytest.mark.options(debug=False)
            def test_something(app):
                assert not app.debug, 'the application works not in debug mode!'

        """
        if 'app' not in request.fixturenames:
            return

>       app = getfixturevalue(request, 'app')

..\anaconda3\envs\mflix\lib\site-packages\pytest_flask\plugin.py:110:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
..\anaconda3\envs\mflix\lib\site-packages\pytest_flask\pytest_compat.py:3: in getfixturevalue
    return request.getfixturevalue(value)
tests\conftest.py:14: in app
    app.config['SECRET_KEY'] = config['TEST']['SECRET_KEY']
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

self = <configparser.ConfigParser object at 0x000002064A3918B0>, key = 'TEST'

    def __getitem__(self, key):
        if key != self.default_section and not self.has_section(key):
>           raise KeyError(key)
E           KeyError: 'TEST'

..\anaconda3\envs\mflix\lib\configparser.py:960: KeyError
============================= 39 tests deselected =============================
=================== 39 deselected, 4 error in 0.60 seconds ====================

(mflix) C:\Users\meirv\mflix-python>

need help here

The line

is certainly wrong.

Thank you for that I fixed that

# Ticket: Connection
# Rename this file to .ini after filling in your MFLIX_DB_URI and your SECRET_KEY
# Do not surround the URI with quotes


[PROD]
SECRET_KEY = super_secret_key_you_should_change
MFLIX_DB_URI = mongodb+srv://m220student:m220password@mflix.0hvvg.mongodb.net/test
MFLIX_NS = sample_mflix

[TEST]
SECRET_KEY = super_secret_testing_key
MFLIX_DB_URI = mongodb+srv://m220student:m220password@mflix.0hvvg.mongodb.net/test
MFLIX_NS = sample_mflix

Still I get the same errors

(mflix2) C:\Users\meirv\mflix-python>pytest -m connection
================================================= test session starts =================================================
platform win32 -- Python 3.8.10, pytest-6.2.4, py-1.10.0, pluggy-0.13.1
rootdir: C:\Users\meirv\mflix-python, configfile: pytest.ini
plugins: flask-0.11.0
collected 43 items / 39 deselected / 4 selected

tests\test_db_connection.py EEEE                                                                                 [100%]

======================================================= ERRORS ========================================================
_________________________________________ ERROR at setup of test_atlas_setup __________________________________________

request = <SubRequest '_configure_application' for <Function test_atlas_setup>>
monkeypatch = <_pytest.monkeypatch.MonkeyPatch object at 0x000002399539DA00>

    @pytest.fixture(autouse=True)
    def _configure_application(request, monkeypatch):
        """Use `pytest.mark.options` decorator to pass options to your application
        factory::

            @pytest.mark.options(debug=False)
            def test_something(app):
                assert not app.debug, 'the application works not in debug mode!'

        """
        if 'app' not in request.fixturenames:
            return

>       app = getfixturevalue(request, 'app')

..\anaconda3\envs\mflix2\lib\site-packages\pytest_flask\plugin.py:110:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
..\anaconda3\envs\mflix2\lib\site-packages\pytest_flask\pytest_compat.py:3: in getfixturevalue
    return request.getfixturevalue(value)
tests\conftest.py:14: in app
    app.config['SECRET_KEY'] = config['TEST']['SECRET_KEY']
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

self = <configparser.ConfigParser object at 0x0000023994E78F70>, key = 'TEST'

    def __getitem__(self, key):
        if key != self.default_section and not self.has_section(key):
>           raise KeyError(key)
E           KeyError: 'TEST'

..\anaconda3\envs\mflix2\lib\configparser.py:960: KeyError
_________________________________________ ERROR at setup of test_basic_movies _________________________________________

request = <SubRequest '_configure_application' for <Function test_basic_movies>>
monkeypatch = <_pytest.monkeypatch.MonkeyPatch object at 0x0000023995436820>

    @pytest.fixture(autouse=True)
    def _configure_application(request, monkeypatch):
        """Use `pytest.mark.options` decorator to pass options to your application
        factory::

            @pytest.mark.options(debug=False)
            def test_something(app):
                assert not app.debug, 'the application works not in debug mode!'

        """
        if 'app' not in request.fixturenames:
            return

>       app = getfixturevalue(request, 'app')

..\anaconda3\envs\mflix2\lib\site-packages\pytest_flask\plugin.py:110:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
..\anaconda3\envs\mflix2\lib\site-packages\pytest_flask\pytest_compat.py:3: in getfixturevalue
    return request.getfixturevalue(value)
tests\conftest.py:14: in app
    app.config['SECRET_KEY'] = config['TEST']['SECRET_KEY']
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

self = <configparser.ConfigParser object at 0x0000023994E78F70>, key = 'TEST'

    def __getitem__(self, key):
        if key != self.default_section and not self.has_section(key):
>           raise KeyError(key)
E           KeyError: 'TEST'

..\anaconda3\envs\mflix2\lib\configparser.py:960: KeyError
______________________________________ ERROR at setup of test_search_by_movie_id ______________________________________

request = <SubRequest '_configure_application' for <Function test_search_by_movie_id>>
monkeypatch = <_pytest.monkeypatch.MonkeyPatch object at 0x000002399548AA90>

    @pytest.fixture(autouse=True)
    def _configure_application(request, monkeypatch):
        """Use `pytest.mark.options` decorator to pass options to your application
        factory::

            @pytest.mark.options(debug=False)
            def test_something(app):
                assert not app.debug, 'the application works not in debug mode!'

        """
        if 'app' not in request.fixturenames:
            return

>       app = getfixturevalue(request, 'app')

..\anaconda3\envs\mflix2\lib\site-packages\pytest_flask\plugin.py:110:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
..\anaconda3\envs\mflix2\lib\site-packages\pytest_flask\pytest_compat.py:3: in getfixturevalue
    return request.getfixturevalue(value)
tests\conftest.py:14: in app
    app.config['SECRET_KEY'] = config['TEST']['SECRET_KEY']
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

self = <configparser.ConfigParser object at 0x0000023994E78F70>, key = 'TEST'

    def __getitem__(self, key):
        if key != self.default_section and not self.has_section(key):
>           raise KeyError(key)
E           KeyError: 'TEST'

..\anaconda3\envs\mflix2\lib\configparser.py:960: KeyError
______________________________________ ERROR at setup of test_simple_text_search ______________________________________

request = <SubRequest '_configure_application' for <Function test_simple_text_search>>
monkeypatch = <_pytest.monkeypatch.MonkeyPatch object at 0x0000023995496C40>

    @pytest.fixture(autouse=True)
    def _configure_application(request, monkeypatch):
        """Use `pytest.mark.options` decorator to pass options to your application
        factory::

            @pytest.mark.options(debug=False)
            def test_something(app):
                assert not app.debug, 'the application works not in debug mode!'

        """
        if 'app' not in request.fixturenames:
            return

>       app = getfixturevalue(request, 'app')

..\anaconda3\envs\mflix2\lib\site-packages\pytest_flask\plugin.py:110:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
..\anaconda3\envs\mflix2\lib\site-packages\pytest_flask\pytest_compat.py:3: in getfixturevalue
    return request.getfixturevalue(value)
tests\conftest.py:14: in app
    app.config['SECRET_KEY'] = config['TEST']['SECRET_KEY']
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

self = <configparser.ConfigParser object at 0x0000023994E78F70>, key = 'TEST'

    def __getitem__(self, key):
        if key != self.default_section and not self.has_section(key):
>           raise KeyError(key)
E           KeyError: 'TEST'

..\anaconda3\envs\mflix2\lib\configparser.py:960: KeyError
================================================== warnings summary ===================================================
..\anaconda3\envs\mflix2\lib\site-packages\flask_cors\core.py:322
  C:\Users\meirv\anaconda3\envs\mflix2\lib\site-packages\flask_cors\core.py:322: DeprecationWarning: Using or importing the ABCs from 'collections' instead of from 'collections.abc' is deprecated since Python 3.3, and in 3.10 it will stop working
    and isinstance(obj, collections.Iterable)):

-- Docs: https://docs.pytest.org/en/stable/warnings.html
=============================================== short test summary info ===============================================
ERROR tests/test_db_connection.py::test_atlas_setup - KeyError: 'TEST'
ERROR tests/test_db_connection.py::test_basic_movies - KeyError: 'TEST'
ERROR tests/test_db_connection.py::test_search_by_movie_id - KeyError: 'TEST'
ERROR tests/test_db_connection.py::test_simple_text_search - KeyError: 'TEST'
===================================== 39 deselected, 1 warning, 4 errors in 0.71s =====================================

(mflix2) C:\Users\meirv\mflix-python>

I got it working it was the .ini file. (Very picky)
Thank you

1 Like

A post was split to a new topic: Certificate_verify_failed m220p

When editing your .ini file make sure you save it as type all files (notepad++) or Notepad

1 Like