'I am running pytest and getting an error - werkzeug.utils.ImportStringError: import_string() failed for 'flask_test.cfg'. Possible reasons are:

I am running pytest by typing python -m pytest

But I get an error FAILED app/tests/functional/test_login.py::test_login_page - werkzeug.utils.ImportStringError: import_string() failed for 'flask_test.cfg'. Possible reasons are:

My code has a lot of comments because I figure you should only test the simplest version of the code. What I mean is when you are starting you should only test 1 line instead of a lot and I didn't realize this right away. The reason I want to include all the comments is to see if that is causing the error.

functional/test_login.py https://pastebin.com/0kxC85WQ

shorter version

from app import create_app


def test_login_page():
    """ 
    GIVEN a Flask application configured for testing
    WHEN the '/login'page requested (GET) 
    THEN check that the response is valid 
    """

    # what is 'flask_test.cfg'?
    flask_app = create_app('flask_test.cfg')
    with flask_app.test_client() as test_client: 
        response = test_client.post('/login')
        assert response.status_code == 405
        
        assert b'Flask User management Example' in response.data

unit/test_models.py https://pastebin.com/AE4Lgc7p

shorter version

from app.models import User 

def test_new_user():
    ''' 
    Given a User model
    When a new user is being logged in
    Check the User database columns
    '''
   
    # username  hashed_password  emai  confirmation_email  reset_email_password 
    user = User('aiohrgihrtg', 'jotpjgjbgt','[email protected]', True, False)
    # Just for testing ?
    assert user.username == 'aiohrgihrtg

'

Here is the tutorial I am using https://testdriven.io/blog/flask-pytest/

my app is structured like the link below

https://github.com/CoreyMSchafer/code_snippets/tree/master/Python/Flask_Blog/11-Blueprints

I am also using conda if that makes a difference.

Thanks for the help.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source