Running pytest -m connection failed

C:\MongoDB\M220\mflix-python>pytest -m connection
============================= test session starts =============================
platform win32 – Python 3.6.5, pytest-3.5.1, py-1.5.3, pluggy-0.6.0
rootdir: C:\MongoDB\M220\mflix-python, inifile:
plugins: remotedata-0.2.1, openfiles-0.3.0, flask-0.10.0, doctestplus-0.1.3, arr
aydiff-0.2
collected 39 items / 35 deselected

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 0x00000000054220F0>

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

on
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 = request.getfuncargvalue('app')

C:\ProgramData\Anaconda3\lib\site-packages\pytest_flask\plugin.py:109:


tests\conftest.py:14: in app
app.config[‘SECRET_KEY’] = config[‘TEST’][‘SECRET_KEY’]


self = <configparser.ConfigParser object at 0x0000000004EED7F0>, key = ‘TEST’

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

E KeyError: ‘TEST’

C:\ProgramData\Anaconda3\lib\configparser.py:959: KeyError
_____________________ ERROR at setup of test_basic_movies _____________________

request = <SubRequest ‘_configure_application’ for <Function ‘test_basic_movies’

monkeypatch = <_pytest.monkeypatch.MonkeyPatch object at 0x00000000056B04E0>

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

on
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 = request.getfuncargvalue('app')

C:\ProgramData\Anaconda3\lib\site-packages\pytest_flask\plugin.py:109:


tests\conftest.py:14: in app
app.config[‘SECRET_KEY’] = config[‘TEST’][‘SECRET_KEY’]


self = <configparser.ConfigParser object at 0x0000000004EED7F0>, key = ‘TEST’

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

E KeyError: ‘TEST’

C:\ProgramData\Anaconda3\lib\configparser.py:959: KeyError
__________________ ERROR at setup of test_search_by_movie_id __________________

request = <SubRequest ‘_configure_application’ for <Function ‘test_search_by_mov
ie_id’>>
monkeypatch = <_pytest.monkeypatch.MonkeyPatch object at 0x00000000054EABE0>

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

on
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 = request.getfuncargvalue('app')

C:\ProgramData\Anaconda3\lib\site-packages\pytest_flask\plugin.py:109:


tests\conftest.py:14: in app
app.config[‘SECRET_KEY’] = config[‘TEST’][‘SECRET_KEY’]


self = <configparser.ConfigParser object at 0x0000000004EED7F0>, key = ‘TEST’

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

E KeyError: ‘TEST’

C:\ProgramData\Anaconda3\lib\configparser.py:959: KeyError
__________________ ERROR at setup of test_simple_text_search __________________

request = <SubRequest ‘_configure_application’ for <Function ‘test_simple_text_s
earch’>>
monkeypatch = <_pytest.monkeypatch.MonkeyPatch object at 0x00000000054FDDD8>

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

on
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 = request.getfuncargvalue('app')

C:\ProgramData\Anaconda3\lib\site-packages\pytest_flask\plugin.py:109:


tests\conftest.py:14: in app
app.config[‘SECRET_KEY’] = config[‘TEST’][‘SECRET_KEY’]


self = <configparser.ConfigParser object at 0x0000000004EED7F0>, key = ‘TEST’

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

E KeyError: ‘TEST’

C:\ProgramData\Anaconda3\lib\configparser.py:959: KeyError
=================== 35 deselected, 4 error in 0.58 seconds ====================

C:\MongoDB\M220\mflix-python>

and as a result I can’t launch command “python run.py”

Hi @alroy,

This is related with your other post. Make sure your .ini is correctly configured has requested in the README lesson, on section Running the Application.

N.

Hi there,

I checked it all twice, but I didn’t fiind any mistake…

maybe the reason is my misunderstanding of IT and what should I do by myself (some obvious things which aren’t described in the lessons)

Thank you

1 Like

Thank you, @Norberto , I have solved this promblem

Hi Norberto,

In the .ini file should we specify our login details as well? Like the username/password combo. The instruction is not clear. Thanks.

Hi all,

We are adding a note to clarify these instructions. Thanks for the feedback!

-Matt

1 Like

@mattjavaly
I want you to assist me solve the issue i encountered in the ticket:projection

Currently am stucked, confused and can’t figure out way forward.
I have read the instructions severely.

Task

Implement the get_movies_by_country method in db.py to search movies by country and use projection to return the title field.

MFlix Functionality

Once you complete this ticket, the UI will allow movie searches by one or more countries.

Testing and Running the Application

Make sure to look at the tests in test_projection.py to understand what is expected.

You can run the unit tests for this ticket by running:
pytest -m projection


Maybe because am not a programmer, which am keen in learning python, can you assist me to understand exactly where exactly in the code on db.py i must modify before i will run the pytest -m projection.

am just stucked here.
Kindly assist me so that i will continue the course. as am eagered in finishing the course but as it stands now, i don’t know what next to do.

I have searched all the forum on m220 to see if anyone encountered same error but none found.

hi Nerberto;

i saw you were helping to other on this issue . i have the same the issue , tried to fixed use the workarounds solution but i doesn’t work on my side . can you help please .

here is my .ini file content
[PROD]
SECRET_KEY = “"
MFLIX_DB_URI = mongodb+srv://m220student:m220password@mflex.rzepg.mongodb.net/db
MFLIX_NS = sample_mflix
[TEST]
SECRET_KEY = "

MFLIX_DB_URI = mongodb+srv://m220student:m220password@mflex.rzepg.mongodb.net/db
MFLIX_NS = sample_mflix

error message :
Traceback (most recent call last):
File “run.py”, line 13, in
app.config[‘MFLIX_DB_URI’] = config[‘PROD’][‘MFLIX_DB_URI’]
File “AppData\Local\Programs\Python\Python37-32\lib\configparser.py”, line 958, in getitem
raise KeyError(key)
KeyError: ‘PROD’

Note: i have tested the connection using “pymongo” driver on jupyternote book and works . in the same way i finished all my M001 assignments on jupyternote book by connecting to atlas.

The same issue when i run the second assignment . (pytest -m projection)
$ pytest -m projection
============================= test session starts =============================
platform win32 – Python 3.7.0, pytest-3.3.0, py-1.8.0, pluggy-0.6.0
rootdir: C:\Users\asfetu\MongoDB\mflix-python, inifile: pytest.ini
plugins: flask-0.11.0
collected 43 items

tests\test_projection.py EE [100%]

=================================== ERRORS ====================================
_______________ ERROR at setup of test_basic_country_search_db ________________

request = <SubRequest ‘_configure_application’ for <Function ‘test_basic_country_search_db’>>
monkeypatch = <_pytest.monkeypatch.MonkeyPatch object at 0x05290B30>

@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')

…\appdata\local\programs\python\python37-32\lib\site-packages\pytest_flask\plugin.py:110:


…\appdata\local\programs\python\python37-32\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 0x04AA2530>, key = ‘TEST’

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

E KeyError: ‘TEST’

…\appdata\local\programs\python\python37-32\lib\configparser.py:958: KeyError
____________ ERROR at setup of test_basic_country_search_shape_db _____________

request = <SubRequest ‘_configure_application’ for <Function ‘test_basic_country_search_shape_db’>>
monkeypatch = <_pytest.monkeypatch.MonkeyPatch object at 0x0535F6F0>

@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')

…\appdata\local\programs\python\python37-32\lib\site-packages\pytest_flask\plugin.py:110:


…\appdata\local\programs\python\python37-32\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 0x04AA2530>, key = ‘TEST’

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

E KeyError: ‘TEST’

…\appdata\local\programs\python\python37-32\lib\configparser.py:958: KeyError
============================= 41 tests deselected =============================
=================== 41 deselected, 2 error in 1.14 seconds ====================

asfetu@DESKTOP-5SC4P9B MINGW64 ~/MongoDB/mflix-python (master)
$ pytest -m projection
============================= test session starts =============================
platform win32 – Python 3.7.0, pytest-3.3.0, py-1.8.0, pluggy-0.6.0
rootdir: C:\Users\asfetu\MongoDB\mflix-python, inifile: pytest.ini
plugins: flask-0.11.0
collected 43 items

tests\test_projection.py EE [100%]

=================================== ERRORS ====================================
_______________ ERROR at setup of test_basic_country_search_db ________________

request = <SubRequest ‘_configure_application’ for <Function ‘test_basic_country_search_db’>>
monkeypatch = <_pytest.monkeypatch.MonkeyPatch object at 0x04F5AC10>

@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')

…\appdata\local\programs\python\python37-32\lib\site-packages\pytest_flask\plugin.py:110:


…\appdata\local\programs\python\python37-32\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 0x04756290>, key = ‘TEST’

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

E KeyError: ‘TEST’

…\appdata\local\programs\python\python37-32\lib\configparser.py:958: KeyError
____________ ERROR at setup of test_basic_country_search_shape_db _____________

request = <SubRequest ‘_configure_application’ for <Function ‘test_basic_country_search_shape_db’>>
monkeypatch = <_pytest.monkeypatch.MonkeyPatch object at 0x0502A410>

@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')

…\appdata\local\programs\python\python37-32\lib\site-packages\pytest_flask\plugin.py:110:


…\appdata\local\programs\python\python37-32\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 0x04756290>, key = ‘TEST’

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

E KeyError: ‘TEST’

…\appdata\local\programs\python\python37-32\lib\configparser.py:958: KeyError
============================= 41 tests deselected =============================
=================== 41 deselected, 2 error in 0.37 seconds ====================

1 Like

Until the connection test works, there is no point in trying the other tests. They all depend on the connection.

Have you activated your virtual environment?

yes steevej.

another error is generated , when i run the application at virtual environment ,
$ python run.py
Traceback (most recent call last):
File “run.py”, line 1, in
from mflix.factory import create_app
File “C:\Users\asfetu\MongoDB\mflix-python\mflix\factory.py”, line 9, in
from bson import json_util, ObjectId
ImportError: cannot import name ‘json_util’ from ‘bson’ (C:\Users\asfetu\MongoDB\mflix-python\mflix_env\lib\site-packages\bson_init_.py)
(mflix_env)

Have you install the requirements with pip?

Can you post a screenshot of running the command cat .ini?

Are you using anaconda or virtualenv? If you are using anaconda, the prompt usually reflects the virtual environment that has been activated. Your prompt simply shows a dollar sign.

hi there;

i reinstalled the requirements.txt , but still the same issue

is there anything that i am supposed to do? get stuck

Earlier we write

But in the screenshot of cat .ini you get the error No such file or directory. It looks like you are missing the step where where it is written to rename a file into .ini.

when should i rename? is that before creating the virtual environment? if so
. i will undo it , renaming after reinstall requirements.txt .

It has to be renamed before running any of the test.

i did. but

thanks steevej-1495
i would like to close this case .solved by redo all process , rename the ini file using bash command (instead of windows explore). finally server is up.

1 Like