Skip to content

Commit

Permalink
test_node_from_parent_kwonly
Browse files Browse the repository at this point in the history
  • Loading branch information
blueyed committed Oct 26, 2020
1 parent 027e773 commit a51448a
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions testing/test_nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,25 @@ def test_ischildnode(baseid, nodeid, expected):
assert result is expected


def test_node_from_parent_kwonly(request: "FixtureRequest") -> None:
"""`Node.from_parent` passes through keyword arguments only.
This can lead to confusing TypeErrors, but is kept like that for (backward) compatibility."""
session = request.session
with pytest.raises(
TypeError,
match=r"__init__\(\) missing 1 required positional argument: 'name'"
):
nodes.Node.from_parent(session)
with pytest.raises(
TypeError,
match=r'^from_parent\(\) takes 2 positional arguments but 3 were given$'
):
nodes.Node.from_parent(session, "myname") # type: ignore[call-arg]
node = nodes.Node.from_parent(session, name="myname")
assert node.name == "myname"


def test_node_from_parent_disallowed_arguments(request: "FixtureRequest") -> None:
msg = "^{} is not a valid argument for from_parent$"
with pytest.raises(TypeError, match=msg.format("session")):
Expand Down

0 comments on commit a51448a

Please sign in to comment.