Slides da palestra sobre py.test apresentada no TDC 2015 na trilha de Python
Slides of my talk about py.test presented at TDC 2015 in the Python track.
http://github.com/erickwilder/pytest-talk
24. def test_something():
> assert {'a': 0, 'b': 1, 'c': 2} == {'a': 0, 'b': 2, 'd': 2}
E assert {'a': 0, 'b': 1, 'c': 2} == {'a': 0, 'b': 2, 'd': 2}
E Omitting 1 identical items, use -v to show
E Differing items:
E {'b': 1} != {'b': 2}
E Left contains more items:
E {'c': 2}
E Right contains more items:
E {'d': 2}
E Use -v to get the full diff
36. from flask import url_for
def test_requires_app_context(app):
url_for('.home') == '/'
def test_config(app): # Same app used
assert 'SQLALCHEMY_DATABASE_URI' in app.config
40. import pytest
def assert_has_config(app, config_key):
__tracebackhide__ = True
if config_key not in app.config:
found_keys = 'n'.join('- {}'.format(key) for key in app.config.keys())
pytest.fail('"{}" config key not found. Found this instead:n'
'{}'.format(config_key, found_keys))
41. app = <Flask 'example.app'>
def test_config_with_helper(app):
> assert_has_config(app, 'SQLALCHEMY_DATABASE_URI')
E Failed: "SQLALCHEMY_DATABASE_URI" config key not found. Found this instead:
E - TESTING
E - JSON_AS_ASCII
E - SESSION_COOKIE_HTTPONLY
E - PRESERVE_CONTEXT_ON_EXCEPTION
E - SESSION_COOKIE_NAME
E - APPLICATION_ROOT
...
E - SESSION_COOKIE_PATH
E - DEBUG