Skip to content

Commit

Permalink
cleaner "raises" checking in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
brondsem committed Jul 12, 2024
1 parent bf82f35 commit c900148
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
3 changes: 2 additions & 1 deletion switchboard/tests/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,8 @@ def test_expirey(self):
def test_no_auto_create(self):
# without auto_create
mydict = MongoModelDict(MockModel, key='key', value='value')
pytest.raises(KeyError, lambda x: x['hello'], mydict)
with pytest.raises(KeyError):
mydict['hello']
assert MockModel.count() == 0

def test_auto_create_no_value(self):
Expand Down
12 changes: 8 additions & 4 deletions switchboard/tests/test_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,8 @@ def test_decorator_for_ip_address(self):
def test():
return True

pytest.raises(HTTPNotFound, test)
with pytest.raises(HTTPNotFound):
test()

switch.status = SELECTIVE
switch.save()
Expand All @@ -170,7 +171,8 @@ def test():
condition='192.168.1.1',
)

pytest.raises(HTTPNotFound, test)
with pytest.raises(HTTPNotFound):
test()

switch.add_condition(
condition_set=condition_set,
Expand Down Expand Up @@ -203,7 +205,8 @@ def test():
condition='0-50',
)

pytest.raises(HTTPNotFound, test)
with pytest.raises(HTTPNotFound):
test()

def test_decorator_with_redirect(self):
Switch.create(
Expand All @@ -218,7 +221,8 @@ def test_decorator_with_redirect(self):
def test():
return True

pytest.raises(HTTPFound, test)
with pytest.raises(HTTPFound):
test()

def test_global(self):
switch = Switch.create(
Expand Down

0 comments on commit c900148

Please sign in to comment.