Skip to content

Commit

Permalink
Add explicit tests of PY2 kw_only SyntaxError behavior.
Browse files Browse the repository at this point in the history
  • Loading branch information
asford committed Jul 28, 2018
1 parent 490bd61 commit 42ec86d
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions tests/test_make.py
Original file line number Diff line number Diff line change
Expand Up @@ -768,6 +768,43 @@ class C(Base):
assert c.y == 1


@pytest.mark.skipif(not PY2, reason="PY2-specific keyword-only error behavior")
class TestKeywordOnlyAttributesOnPy2(object):
"""
Tests for keyword-only attribute behavior on py2.
"""

def test_syntax_error(self):
"""
Keyword-only attributes raise Syntax error on ``__init__`` generation.
"""

with pytest.raises(SyntaxError):

@attr.s(kw_only=True)
class ClassLevel(object):
a = attr.ib()

with pytest.raises(SyntaxError):

@attr.s()
class AttrLevel(object):
a = attr.ib(kw_only=True)

def test_no_init(self):
"""
Keyworld-only is a no-op, not any error, if ``init=false``.
"""

@attr.s(kw_only=True, init=False)
class ClassLevel(object):
a = attr.ib()

@attr.s(init=False)
class AttrLevel(object):
a = attr.ib(kw_only=True)


@attr.s
class GC(object):
@attr.s
Expand Down

0 comments on commit 42ec86d

Please sign in to comment.