Search code examples
python-3.xtestingconfigurationsanic

Sanic how to load confguration for test app?


I want my test server to have a dummy config variables

I have the following fixture:


@pytest.fixture
def server():
    app.config.thing =1 #the dummy var
    return app.test_client

And a test

def test_thing(server):

    assert server.config.thing == 1

I get the following error:

AttributeError: 'SanicTestClient' object has no attribute 'config`

How do I fix this?


Solution

  • SanicTestClient is a wrapper around the app - it's not the app itself. So simply do assert server.app.config.thing == 1