So I've tried writing some tests for my Flask application for a couple of days but I can't get it to run. The tests pass but it gets stuck on PASSED.
I've cloned cookiecutter-flask (cookiecutter-flask) and it runs webtest together with pytest (I think). My conftest.py looks the same as it does in the repo (conftest.py)
These are my current tests:
def test_app(testapp):
app = create_app(TestConfig)
res = testapp.get('/')
res.status_code == 200
This pass and it continues.
def test_create_admin_user(db, testapp):
password = bcrypt.generate_password_hash('test')
User.create(
uid='00000000000000000000',
email='john@doe.com',
password=password,
active=1
)
user = User.query.filter_by(email='j@d.com').first()
assert user.email == 'j@d.com'
This is where I'm lost and the test gets stuck on PASSED and doesn't do anything. When I force interrupt the process I get this:
Traceback (most recent call last):
File "manage.py", line 68, in <module>
manager.run()
File "/home/johan/Development/venv_python/local/lib/python2.7/site-packages/flask_script/__init__.py", line 412, in run
result = self.handle(sys.argv[0], sys.argv[1:])
File "/home/johan/Development/venv_python/local/lib/python2.7/site-packages/flask_script/__init__.py", line 383, in handle
res = handle(*args, **config)
File "/home/johan/Development/venv_python/local/lib/python2.7/site-packages/flask_script/commands.py", line 216, in __call__
return self.run(*args, **kwargs)
File "/home/johan/Development/venv_python/local/lib/python2.7/site-packages/flask/ctx.py", line 386, in __exit__
self.auto_pop(exc_value)
File "/home/johan/Development/venv_python/local/lib/python2.7/site-packages/flask/ctx.py", line 374, in auto_pop
self.pop(exc)
File "/home/johan/Development/venv_python/local/lib/python2.7/site-packages/flask/ctx.py", line 357, in pop
% (rv, self)
AssertionError: Popped wrong request context. (<RequestContext 'http://localhost/' [GET] of backend.app> instead of <RequestContext 'http://localhost/' [GET] of backend.app>)
I've found the following thread in flask about testing (granted, this is Flask-Testing but I thought that it has some relevance, maybe it doesn't: issue) and changed my test-config so it contains PRESERVE_CONTEXT_ON_EXCEPTION = False but it still just hangs.
Anybody have any ideas I can try? I'm not super familiar with testing per se so it probably is something that I'm doing wrong.