Not able to run unit test for Projection

I am trying to run it through PyCharm and I am getting the following key error,

Testing started at 22:42 …
C:\Users\Abhishek\M220P\mflix-python\venv\Scripts\python.exe “C:\Program Files\JetBrains\PyCharm Community Edition 2019.2\helpers\pycharm_jb_pytest_runner.py” --target test_projection.py::test_basic_country_search_db
Launching pytest with arguments test_projection.py::test_basic_country_search_db in C:\Users\Abhishek\M220P\mflix-python\tests

============================= test session starts =============================
platform win32 – Python 3.7.0, pytest-3.3.0, py-1.8.0, pluggy-0.6.0 – C:\Users\Abhishek\M220P\mflix-python\venv\Scripts\python.exe
cachedir: .cache
rootdir: C:\Users\Abhishek\M220P\mflix-python\tests, inifile:
plugins: flask-0.10.0
collecting … collected 1 item

test_projection.py::test_basic_country_search_db ERROR [100%]
test setup failed
request = <SubRequest ‘_configure_application’ for <Function ‘test_basic_country_search_db’>>
monkeypatch = <_pytest.monkeypatch.MonkeyPatch object at 0x04644C50>

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

…\AppData\Local\Programs\Python\Python37-32\lib\site-packages\pytest_flask\plugin.py:109:


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


self = <configparser.ConfigParser object at 0x03DFFBD0>, 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

=================================== 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 0x04644C50>

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

…\AppData\Local\Programs\Python\Python37-32\lib\site-packages\pytest_flask\plugin.py:109:


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


self = <configparser.ConfigParser object at 0x03DFFBD0>, 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
=========================== 1 error in 0.21 seconds ===========================

Process finished with exit code 0

Assertion failed

Assertion failed

But i was able to run the integration test for this ticket.
Can someone please help me here to run the unit tests.

Thanks You!

Perhaps you did not set your .ini file as indicated.

Thanks for the reply,
But I have already updated my .ini file as,

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 = q5vggqn9ozzkgiredlsaqfilwoy9976finu50464
MFLIX_DB_URI = mongodb+srv://m220student:m220password@(my_cluster_string)
MFLIX_NS = sample_mflix

[TEST]
SECRET_KEY = qfilwoy9976finu50464q5vggqn9ozzkgiredlsa
MFLIX_DB_URI = mongodb+srv://m220student:m220password@(my_cluster_string)
MFLIX_NS = sample_mflix

But not sure why i am getting the key error only in case of running the unit test but integration test is getting passed.

I was using pytest to run the test as indicated in the course material. May be pycharm is not using .ini in the same way.