Skip to content

Commit

Permalink
Updated a check_args method.
Browse files Browse the repository at this point in the history
Now the name of an argument that causes assertion failure should be
obtainable.
  • Loading branch information
Evildoor committed Nov 19, 2018
1 parent 4c1c44a commit e1343c5
Showing 1 changed file with 7 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,13 @@ def tearDown(self):

def check_args(self, args):
for a in args:
self.assertEqual(getattr(self.stage.ARGS, a), args[a])
# Such kind of testing does not display the argument's name,
# hence the "a + '_'" addition.
if isinstance(args[a], str):
self.assertEqual(a + '_' + getattr(self.stage.ARGS, a),
a + '_' + args[a])
else:
self.assertEqual(getattr(self.stage.ARGS, a), args[a])

This comment has been minimized.

Copy link
@mgolosova

mgolosova Nov 20, 2018

Collaborator

What about this:

assertEqual({a: getattr(self.stage.ARGS, a)}, {a: args[a]})`

?
It will produce the following output:

$ python -m unittest discover
<...>
AssertionError: {'dest': 'f'} != {'dest': 's'}
- {'dest': 'f'}
?           ^

+ {'dest': 's'}
?  
<...>

-- still looks readable (for me) and does not require the value to be a string.

This comment has been minimized.

Copy link
@Evildoor

Evildoor Nov 20, 2018

Author Contributor

Yes, this looks better to me. Thanks, will do.


def test_default(self):
self.stage.parse_args('')
Expand Down

0 comments on commit e1343c5

Please sign in to comment.