remove pytest.mark.usefixtures decorator

while it's nice to use the decorator to signify fixtures with side
effects, it has unfortunate problems of completely overriding any
fixtures you've declared in the funcargs - so isn't really suitable
for our usecase where we often have other fixtures we rely on to
return values to us.

So for consistency, let's remove this and stick to using funcargs
to define our fixtures
This commit is contained in:
Leo Hemsted
2017-01-10 15:00:10 +00:00
parent 44a8526807
commit 0f327a0995
2 changed files with 10 additions and 15 deletions

View File

@@ -21,8 +21,7 @@ from app.models import User, VerifyCode
from tests.app.db import create_user from tests.app.db import create_user
@pytest.mark.usefixtures('notify_db_session') def test_create_user(notify_db_session):
def test_create_user():
email = 'notify@digital.cabinet-office.gov.uk' email = 'notify@digital.cabinet-office.gov.uk'
data = { data = {
'name': 'Test User', 'name': 'Test User',
@@ -38,8 +37,7 @@ def test_create_user():
assert not user.platform_admin assert not user.platform_admin
@pytest.mark.usefixtures('notify_db_session') def test_get_all_users(notify_db_session):
def test_get_all_users():
create_user(email='1@test.com') create_user(email='1@test.com')
create_user(email='2@test.com') create_user(email='2@test.com')
@@ -47,21 +45,18 @@ def test_get_all_users():
assert len(get_user_by_id()) == 2 assert len(get_user_by_id()) == 2
@pytest.mark.usefixtures('notify_db_session') def test_get_user(notify_db_session):
def test_get_user():
email = '1@test.com' email = '1@test.com'
user = create_user(email=email) user = create_user(email=email)
assert get_user_by_id(user_id=user.id).email_address == email assert get_user_by_id(user_id=user.id).email_address == email
@pytest.mark.usefixtures('notify_db_session') def test_get_user_not_exists(notify_db_session, fake_uuid):
def test_get_user_not_exists(fake_uuid):
with pytest.raises(NoResultFound): with pytest.raises(NoResultFound):
get_user_by_id(user_id=fake_uuid) get_user_by_id(user_id=fake_uuid)
@pytest.mark.usefixtures('notify_db_session') def test_get_user_invalid_id(notify_db_session):
def test_get_user_invalid_id():
with pytest.raises(DataError): with pytest.raises(DataError):
get_user_by_id(user_id="blah") get_user_by_id(user_id="blah")

View File

@@ -10,8 +10,8 @@ def create_user(mobile_number="+447700900986", email="notify@digital.cabinet-off
'mobile_number': mobile_number, 'mobile_number': mobile_number,
'state': 'active' 'state': 'active'
} }
usr = User.query.filter_by(email_address=email).first() user = User.query.filter_by(email_address=email).first()
if not usr: if not user:
usr = User(**data) user = User(**data)
save_model_user(usr) save_model_user(user)
return usr return user