No tests ran in 0.01s

Hi,

I’m currently facing the same issue as ERROR at setup of test_atlas_setup. I am working off my local MongoDB.

  1. M220P website runs.

  2. pytest.exe -m connection fails with same errors in original post.

I tried:

  1. updated dnspython to 1.16.0

  2. In tests/pycache: removed everything.

  3. Ran pytest tests/test_db_connection.py --fixtures

Please see output:

============================= test session starts =============================
platform win32 -- Python 3.10.1, pytest-7.0.1, pluggy-1.0.0
rootdir: F:\Codes\Python\virtual\mflix, configfile: pytest.ini
collected 4 items
cache -- ...\_pytest\cacheprovider.py:510
    Return a cache object that can persist state between testing sessions.

capsys -- ...\_pytest\capture.py:878
    Enable text capturing of writes to ``sys.stdout`` and ``sys.stderr``.

capsysbinary -- ...\_pytest\capture.py:895
    Enable bytes capturing of writes to ``sys.stdout`` and ``sys.stderr``.

capfd -- ...\_pytest\capture.py:912
    Enable text capturing of writes to file descriptors ``1`` and ``2``.

capfdbinary -- ...\_pytest\capture.py:929
    Enable bytes capturing of writes to file descriptors ``1`` and ``2``.

doctest_namespace [session scope] -- ...\_pytest\doctest.py:731
    Fixture that returns a :py:class:`dict` that will be injected into the
    namespace of doctests.

pytestconfig [session scope] -- ...\_pytest\fixtures.py:1365
    Session-scoped fixture that returns the session's :class:`pytest.Config`
    object.

record_property -- ...\_pytest\junitxml.py:282
    Add extra properties to the calling test.

record_xml_attribute -- ...\_pytest\junitxml.py:305
    Add extra xml attributes to the tag for the calling test.

record_testsuite_property [session scope] -- ...\_pytest\junitxml.py:343
    Record a new ``<property>`` tag as child of the root ``<testsuite>``.

tmpdir_factory [session scope] -- ...\_pytest\legacypath.py:295
    Return a :class:`pytest.TempdirFactory` instance for the test session.

tmpdir -- ...\_pytest\legacypath.py:302
    Return a temporary directory path object which is unique to each test
    function invocation, created as a sub directory of the base temporary
    directory.

caplog -- ...\_pytest\logging.py:483
    Access and control log capturing.

monkeypatch -- ...\_pytest\monkeypatch.py:29
    A convenient fixture for monkey-patching.

recwarn -- ...\_pytest\recwarn.py:29
    Return a :class:`WarningsRecorder` instance that records all warnings emitted by test functions.

tmp_path_factory [session scope] -- ...\_pytest\tmpdir.py:183
    Return a :class:`pytest.TempPathFactory` instance for the test session.

tmp_path -- ...\_pytest\tmpdir.py:198
    Return a temporary directory path object which is unique to each test
    function invocation, created as a sub directory of the base temporary
    directory.


-------------------- fixtures defined from tests.conftest ---------------------
app -- tests\conftest.py:12
    no docstring available


============================ no tests ran in 0.01s ============================

Thank you and best regards,

Be Hai Nguyen.

Hey @Be_Hai_Nguyen,

It seems as if no tests ran from the Output you shared. Can you share your .ini file and the code you did? Also, Did you try installing all packages from the requirements.txt file?

Can you explain this further? The tests require that you create and are connected to an Atlas Cluster without which the tests will fail.

Regards,
Satyam

1 Like

Hi Satyam,

Thank you for your response. I have been able to get pass this now.

– And yes, you are right, on my initial reply above: there was no tests ran at all.

There seems to be a number of issues associated with the provided test codes. The one thing I am confident to say so far is that the conftest.py missing two crucial fixtures: config and client. I have to add them in. I am using Python 3.10.2, I have installed packages in supplied requirements.txt successfully.

Please find below my conftest.py. After I finish this M220 course, I will do a full WordPress post on this.

Thank you and best regards.


import pytest
from mflix.factory import create_app

import os
import configparser

__config = configparser.ConfigParser()
__config.read(os.path.abspath(os.path.join(".ini")))

“”"
with open( ‘__config.txt’, ‘w’ ) as f:
f.write( ‘PROD.SECRET_KEY: {}’.format(__config[‘PROD’][‘SECRET_KEY’]) )
f.write( ‘\nPROD.MFLIX_DB_URI: {}’.format(__config[‘PROD’][‘MFLIX_DB_URI’]) )
f.write( ‘\nPROD.MFLIX_NS: {}’.format(__config[‘PROD’][‘MFLIX_NS’]) )
f.write( ‘\nTEST.SECRET_KEY: {}’.format(__config[‘TEST’][‘SECRET_KEY’]) )
f.write( ‘\nTEST.MFLIX_DB_URI: {}’.format(__config[‘TEST’][‘MFLIX_DB_URI’]) )
f.write( ‘\nTEST.MFLIX_NS: {}’.format(__config[‘TEST’][‘MFLIX_NS’]) )

f.close()

“”"

@pytest.fixture
def config():
cfg = configparser.ConfigParser()
cfg.read( os.path.abspath(os.path.join(".ini")) )

"""
with open( 'conftest_config.txt', 'w' ) as f:
    f.write( 'PROD.SECRET_KEY: {}'.format(cfg['PROD']['SECRET_KEY']) )
    f.write( '\nPROD.MFLIX_DB_URI: {}'.format(cfg['PROD']['MFLIX_DB_URI']) )
    f.write( '\nPROD.MFLIX_NS: {}'.format(cfg['PROD']['MFLIX_NS']) )
    f.write( '\nTEST.SECRET_KEY: {}'.format(cfg['TEST']['SECRET_KEY']) )
    f.write( '\nTEST.MFLIX_DB_URI: {}'.format(cfg['TEST']['MFLIX_DB_URI']) )
    f.write( '\nTEST.MFLIX_NS: {}'.format(cfg['TEST']['MFLIX_NS']) )

    f.close()
"""

return cfg

@pytest.fixture
def client():
flask_app = create_app()

flask_app.config['SECRET_KEY'] = __config['TEST']['SECRET_KEY']
flask_app.config['MFLIX_NS'] = __config['PROD']['MFLIX_NS']
flask_app.config['MFLIX_DB_URI'] = __config['TEST']['MFLIX_DB_URI']

# Create a test client using the Flask application configured for testing
with flask_app.test_client() as testing_client:
    # Establish an application context
    with flask_app.app_context():
        yield testing_client  # this is where the testing happens!

@pytest.fixture
def app():
app = create_app()
app.config[‘SECRET_KEY’] = __config[‘TEST’][‘SECRET_KEY’]
app.config[‘MFLIX_NS’] = __config[‘PROD’][‘MFLIX_NS’]
app.config[‘MFLIX_DB_URI’] = __config[‘TEST’][‘MFLIX_DB_URI’]
return app

1 Like

Hey @Be_Hai_Nguyen,

Happy to know the issue got resolved. Hope you are enjoying the course and finding it informative and useful. :dizzy:

Please feel free to reach out for anything else as well.

Regards,
Satyam

1 Like

Hi Satyam,

Thank you for your response. I did enjoy the course, I find it very useful too…

There are still a few issues regarding the MFLIX course application, I am working on these still… Hopefully I can resolve them: all these issues have been reported to this forum too, my issues are not new.

Thank you and best regards,

…behai.

1 Like

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.