Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Preserve the order of parameterized arguments #401

Merged
merged 3 commits into from
Mar 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions nox/_parametrize.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,7 @@ def __str__(self) -> str:
return self.id
else:
call_spec = self.call_spec
keys = sorted(call_spec.keys(), key=str)
args = ["{}={}".format(k, repr(call_spec[k])) for k in keys]
args = ["{}={}".format(k, repr(call_spec[k])) for k in call_spec.keys()]
return ", ".join(args)

__repr__ = __str__
Expand Down
14 changes: 7 additions & 7 deletions tests/test__parametrize.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,19 +200,19 @@ def test_generate_calls_multiple_args():
f = mock.Mock()
f.__name__ = "f"

arg_names = ("abc", "foo")
arg_names = ("foo", "abc")
call_specs = [
_parametrize.Param(1, "a", arg_names=arg_names),
_parametrize.Param(2, "b", arg_names=arg_names),
_parametrize.Param(3, "c", arg_names=arg_names),
_parametrize.Param("a", 1, arg_names=arg_names),
_parametrize.Param("b", 2, arg_names=arg_names),
_parametrize.Param("c", 3, arg_names=arg_names),
]

calls = _decorators.Call.generate_calls(f, call_specs)

assert len(calls) == 3
assert calls[0].session_signature == "(abc=1, foo='a')"
assert calls[1].session_signature == "(abc=2, foo='b')"
assert calls[2].session_signature == "(abc=3, foo='c')"
assert calls[0].session_signature == "(foo='a', abc=1)"
assert calls[1].session_signature == "(foo='b', abc=2)"
assert calls[2].session_signature == "(foo='c', abc=3)"

calls[0]()
f.assert_called_with(abc=1, foo="a")
Expand Down