-1

I have a Flask server that has server.py set up in the following way

server.py

app = Flask(__name__)
app.register_blueprint(mybp)
if __name__ == '__main__':
    app.config.foo = "bar"

mybp.py

@mybp.route('/', methods=['POST'])
def root():
    return app.config.foo

test.py

@pytest.fixture
def client():
    server.app.config['TESTING'] = True
    client = server.app.test_client()
    client
    yield client

def testbp(client):
    client.post('/mybp')

When I run the test, I get the following error

E       AttributeError: 'Config' object has no attribute 'foo'

because the configuration hasn't been initialized when running the test.

davidism
  • 121,510
  • 29
  • 395
  • 339
Carpetfizz
  • 8,707
  • 22
  • 85
  • 146

1 Answers1

0

You're already initialising a config value 'TESTING' in your test file. So why not initialise your config for the test there as well

@pytest.fixture
def client():
    server.app.config.foo = "bar"
    server.app.config['TESTING'] = True
    client = server.app.test_client()
    client
    yield client

def testbp(client):
    client.post('/mybp')

Also you're posting to the endpoint /mybp but you're endpoint in mybp.py is for /

Tim Thompson
  • 301
  • 2
  • 7