Skip to content

Commit 42ec86d

Browse files
author
Alex Ford
committed
Add explicit tests of PY2 kw_only SyntaxError behavior.
1 parent 490bd61 commit 42ec86d

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

tests/test_make.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -768,6 +768,43 @@ class C(Base):
768768
assert c.y == 1
769769

770770

771+
@pytest.mark.skipif(not PY2, reason="PY2-specific keyword-only error behavior")
772+
class TestKeywordOnlyAttributesOnPy2(object):
773+
"""
774+
Tests for keyword-only attribute behavior on py2.
775+
"""
776+
777+
def test_syntax_error(self):
778+
"""
779+
Keyword-only attributes raise Syntax error on ``__init__`` generation.
780+
"""
781+
782+
with pytest.raises(SyntaxError):
783+
784+
@attr.s(kw_only=True)
785+
class ClassLevel(object):
786+
a = attr.ib()
787+
788+
with pytest.raises(SyntaxError):
789+
790+
@attr.s()
791+
class AttrLevel(object):
792+
a = attr.ib(kw_only=True)
793+
794+
def test_no_init(self):
795+
"""
796+
Keyworld-only is a no-op, not any error, if ``init=false``.
797+
"""
798+
799+
@attr.s(kw_only=True, init=False)
800+
class ClassLevel(object):
801+
a = attr.ib()
802+
803+
@attr.s(init=False)
804+
class AttrLevel(object):
805+
a = attr.ib(kw_only=True)
806+
807+
771808
@attr.s
772809
class GC(object):
773810
@attr.s

0 commit comments

Comments
 (0)