Skip to content
Myr

Merge pull request #2311 from bovarysme/use-yield-syntax

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Use the yield syntax in pytest's fixtures

authored by David Lord · committed by GitHub · parents e206764, 5963cb5 · Browse files · 3 files+25 added−28 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

3 files+25 added−28 removed

  • tests:+25 added−28 removed

3 files+25 added−28 removed

modified:examples/minitwit/tests/test_minitwit.py+5 added-7 removed
13 unmodified lines
14from minitwit import minitwit151617@pytest.fixture18def client(request):18def client():19 db_fd, minitwit.app.config['DATABASE'] = tempfile.mkstemp()20 client = minitwit.app.test_client()21 with minitwit.app.app_context():22 minitwit.init_db()2324 def teardown():25 """Get rid of the database again after each test."""26 os.close(db_fd)27 os.unlink(minitwit.app.config['DATABASE'])28 request.addfinalizer(teardown)29 return client24 yield client2526 os.close(db_fd)27 os.unlink(minitwit.app.config['DATABASE'])282930def register(client, username, password, password2=None, email=None):31 """Helper function to register a user"""32 if password2 is None:33 password2 = password
116 unmodified lines
modified:tests/conftest.py+10 added-9 removed
20 unmodified lines
21 os.path.abspath(os.path.join(22 os.path.dirname(__file__), 'test_apps'))23 )242526@pytest.fixture(autouse=True)26def leak_detector(request):27 def ensure_clean_request_context():28 # make sure we're not leaking a request context since we are29 # testing flask internally in debug mode in a few cases30 leaks = []31 while flask._request_ctx_stack.top is not None:32 leaks.append(flask._request_ctx_stack.pop())33 assert leaks == []34 request.addfinalizer(ensure_clean_request_context)27def leak_detector():28 yield2930 # make sure we're not leaking a request context since we are31 # testing flask internally in debug mode in a few cases32 leaks = []33 while flask._request_ctx_stack.top is not None:34 leaks.append(flask._request_ctx_stack.pop())35 assert leaks == []363738@pytest.fixture(params=(True, False))39def limit_loader(request, monkeypatch):40 """Patch pkgutil.get_loader to give loader without get_filename or archive.41
94 unmodified lines
modified:tests/test_ext.py+10 added-12 removed
19 unmodified lines
20from flask._compat import PY2212223@pytest.fixture(autouse=True)24def disable_extwarnings(request, recwarn):24def disable_extwarnings(recwarn):25 from flask.exthook import ExtDeprecationWarning2627 def inner():28 assert set(w.category for w in recwarn.list) \29 <= set([ExtDeprecationWarning])30 recwarn.clear()27 yield2832 request.addfinalizer(inner)29 assert set(w.category for w in recwarn.list) \30 <= set([ExtDeprecationWarning])31 recwarn.clear()323334@pytest.fixture(autouse=True)36def importhook_setup(monkeypatch, request):35def importhook_setup(monkeypatch):36 # we clear this out for various reasons. The most important one is37 # that a real flaskext could be in there which would disable our38 # fake package. Secondly we want to make sure that the flaskext39 # import hook does not break on reloading.
16 unmodified lines
56 cls.__name__ == 'ExtensionImporter':57 import_hooks += 158 assert import_hooks == 15961 def teardown():62 from flask import ext63 for key in ext.__dict__:64 assert '.' not in key60 yield6166 request.addfinalizer(teardown)62 from flask import ext63 for key in ext.__dict__:64 assert '.' not in key656667@pytest.fixture68def newext_simple(modules_tmpdir):
129 unmodified lines