← Back to DAGDA | Support | Source: https://github.com/pytest-dev/pytest/issues/744
Skip to content

py.test assert rewriting broken with Python 3.5a4+ #744

Closed

Description

@pytestbot

Originally reported by: BitBucket: gvanrossum, GitHub: gvanrossum


I am experiencing a traceback ending thus:

/usr/local/lib/python3.5/site-packages/_pytest/assertion/rewrite.py:137: in find_module
    source_stat, co = _rewrite_test(state, fn_pypath)
/usr/local/lib/python3.5/site-packages/_pytest/assertion/rewrite.py:278: in _rewrite_test
    rewrite_asserts(tree)
/usr/local/lib/python3.5/site-packages/_pytest/assertion/rewrite.py:336: in rewrite_asserts
    AssertionRewriter().run(mod)
/usr/local/lib/python3.5/site-packages/_pytest/assertion/rewrite.py:550: in run
    new.extend(self.visit(child))
/usr/local/lib/python3.5/ast.py:245: in visit
    return visitor(node)
/usr/local/lib/python3.5/site-packages/_pytest/assertion/rewrite.py:658: in visit_Assert
    top_condition, explanation = self.visit(assert_.test)
/usr/local/lib/python3.5/ast.py:245: in visit
    return visitor(node)
/usr/local/lib/python3.5/site-packages/_pytest/assertion/rewrite.py:789: in visit_Compare
    left_res, left_expl = self.visit(comp.left)
/usr/local/lib/python3.5/ast.py:245: in visit
    return visitor(node)
/usr/local/lib/python3.5/site-packages/_pytest/assertion/rewrite.py:640: in generic_visit
    return res, self.explanation_param(self.display(res))
/usr/local/lib/python3.5/site-packages/_pytest/assertion/rewrite.py:577: in display
    return self.helper("saferepr", expr)
/usr/local/lib/python3.5/site-packages/_pytest/assertion/rewrite.py:583: in helper
    return ast.Call(attr, list(args), [], None, None)
E   TypeError: Call constructor takes either 0 or 3 positional arguments

I get this as soon as I have an assert statement in my test (even assert True).


Activity

  1. pytestbot commented on May 17, 2015

    @pytestbot
    ContributorAuthor

    Original comment by Matthias Bussonnier (BitBucket: Carreau, GitHub: Carreau):


    This is due to 95886 , that fixes Missing *-unpacking generalizations and change the signature of _ast.Call as far as I can tell. I guess the change of signature might have to be added in What's new, or someone should add compatibility layer in ast.

  2. pytestbot commented on May 17, 2015

    @pytestbot
    ContributorAuthor

    Original comment by BitBucket: gvanrossum, GitHub: gvanrossum:


    But are you going to fix it? There is no compatibility guarantee for the ast module.

  3. pytestbot commented on May 17, 2015

    @pytestbot
    ContributorAuthor

    Original comment by Matthias Bussonnier (BitBucket: Carreau, GitHub: Carreau):


    I don't know, I came across the same bug this morning, found this issue and started digging, I have never contributed to pytest either so I'm not that familiar with the codebase. The AST has no compat and not a lot of docs either, but I achieved to get a partial workaround here for now.NOt sure I have a lot of time to put on that next week, but I'll try. After it might be a start point for the maintainers of pytest.

  4. pytestbot commented on May 17, 2015

    @pytestbot
    ContributorAuthor

    Original comment by BitBucket: gvanrossum, GitHub: gvanrossum:


    Oh, sorry. I don't know who's who on the project, and since you were the first and only one to reply to the bug, I assumed you were one of the maintainers. :-) Thanks for the fix!

  5. pytestbot commented on May 17, 2015

    @pytestbot
    ContributorAuthor

    Original comment by Matthias Bussonnier (BitBucket: Carreau, GitHub: Carreau):


    No problem, the same happen to me often. Thanks for CPython in general, pushing people toward 3.5 as much as I can !

  6. pytestbot commented on May 18, 2015

    @pytestbot
    ContributorAuthor

    Original comment by Thomas Kluyver (BitBucket: takluyver, GitHub: takluyver):


    Re not a lot of docs: I maintain some extra documentation about working with ASTs at http://greentreesnakes.readthedocs.org/en/latest/ , though it doesn't yet describe Python 3.5. Pull requests welcome, especially once 3.5 is a bit closer to release.

  7. pytestbot commented on May 18, 2015

    @pytestbot
    ContributorAuthor

    Original comment by Matthias Bussonnier (BitBucket: Carreau, GitHub: Carreau):


    Yes, I just cloned it to potentially make some adjustements. I'm also reading about Argument Clinic to see if some docs could be added to _ast in C source in 3.5. Though I haven't touched C in almost a decade already.

  8. pytestbot commented on Jun 3, 2015

    @pytestbot
    ContributorAuthor

    Original comment by holger krekel (BitBucket: hpk42, GitHub: hpk42):


    For the record, work is ongoing at https://bitbucket.org/pytest-dev/pytest/pull-request/296/astcall-signature-changed-on-35/diff , thanks to Matthias. Hopefully we can merge it soon and release pytest-2.7.2 with it.

  9. added
    type: bug
    on Jun 15, 2015
  10. warsaw commented on Jun 19, 2015

    @warsaw

    In Ubuntu, we're doing a test rebuild with Python 3.5 as the default Python 3 version:

    https://launchpad.net/~pythoneers/+archive/ubuntu/py35asdefault/+packages?batch=75

    At least some of the failures are due to this but (which affects the test suites of those packages run at build time). I'll watch this bug and try to hotfix our pytest package for the rebuild once a patch is available.

  11. warsaw commented on Jun 23, 2015

    @warsaw

    @dstufft says: --assert=plain may help temporarily.

  12. warsaw commented on Jun 23, 2015

    @warsaw

    I looked at that bitbucket patch and unfortunately it doesn't make the test suite pass for me with Python 3.5

  13. jonathaneunice commented on Jul 7, 2015

    @jonathaneunice

    Just reconfirmed the bug. Still an issue with Python 3.5.0b3 (released July 5).

    This is a show-stopper for me doing any work with 3.5. I can't proceed without a working test rig.

  14. The-Compiler commented on Jul 8, 2015

    @The-Compiler
    Member

    @jonathaneunice as a workaround, you can use --assert=plain until this is fixed.

  15. warsaw commented on Jul 10, 2015

    @warsaw

    I'm curious whether anyone is actively working on this issue. It's definitely the top related failure I'm seeing in our Ubuntu Python 3.5 test rebuilds.

  16. 29 remaining items

  17. The-Compiler commented on Sep 15, 2015

    @The-Compiler
    Member

    @ByteCommander it was already fixed in July in #801, and a new pytest version (2.7.3) with the fix was released today.

    So your best bet would be to update 😉 As a workaround, as mentioned earlier in this thread, you can use --assert=plain

  18. flub commented on Sep 16, 2015

    @flub
    Member

    py.test 2.7.3 has been released with support for Python 3.5
    On 15 Sep 2015 21:53, "Barry Warsaw" notifications@github.com wrote:

    Here's the patch currently applied to the Debian version. I don't know if
    this is what upstream will commit, but it works for us in the meantime:
    https://alioth.debian.org/scm/viewvc.php/packages/pytest/trunk/debian/patches/issue744-py35-compat?view=markup&revision=33376&root=python-modules

    —
    Reply to this email directly or view it on GitHub
    #744 (comment).

  19. warsaw commented on Sep 16, 2015

    @warsaw

    On Sep 16, 2015, at 03:47 AM, Floris Bruynooghe wrote:

    py.test 2.7.3 has been released with support for Python 3.5

    Thanks for that! Debian now has this version without the custom patch. :)

  20. Toilal commented on Sep 18, 2015

    @Toilal
    Contributor

    For people using travis CI, use this command in travis.yml

    install:
      - pip install pytest>=2.7.3 --upgrade
    
  21. bmorris3 commented on Apr 4, 2016

    @bmorris3

    @Toilal Any updates on your recommendation above? I'm still getting the originally posted traceback after using your fix.

  22. Toilal commented on Apr 4, 2016

    @Toilal
    Contributor

    I don't know. I've dropped python 3.5 support in my projects.
    Le 4 avr. 2016 20:44, "Brett M. Morris" notifications@github.com a écrit :

    @Toilal https://github.com/Toilal Any updates on your recommendation
    above? I'm still getting the originally posted traceback after using your
    fix.

    —
    You are receiving this because you were mentioned.
    Reply to this email directly or view it on GitHub
    #744 (comment)

  23. Toilal commented on Apr 4, 2016

    @Toilal
    Contributor

    No sorry, i've read 2.5 instead of 3.5. 3.5 is still supported of course,
    but it doesn't cause any issue with latest pytest I think.
    Le 4 avr. 2016 21:06, "Rémi Alvergnat" toilal.dev@gmail.com a écrit :

    I don't know. I've dropped python 3.5 support in my projects.
    Le 4 avr. 2016 20:44, "Brett M. Morris" notifications@github.com a
    écrit :

    @Toilal https://github.com/Toilal Any updates on your recommendation
    above? I'm still getting the originally posted traceback after using your
    fix.

    —
    You are receiving this because you were mentioned.
    Reply to this email directly or view it on GitHub
    #744 (comment)

  24. The-Compiler commented on Apr 4, 2016

    @The-Compiler
    Member

    @bmorris3 Looking at https://travis-ci.org/bmorris3/shampoo/jobs/120545149 you're running pytest 2.5.1, which is from December 2013. This was fixed in 2.7.3, and the current release is 2.9.1. In other words, please upgrade 😉

  25. bmorris3 commented on Apr 4, 2016

    @bmorris3

    Thanks for pointing that out – I don't understand why my inclusion of:

    install:
      - pip install pytest>=2.7.3 --upgrade
    

    in my .travis.yml didn't upgrade to the latest pip, but that's on me for figuring out.

  26. dstufft commented on Apr 5, 2016

    @dstufft

    I think that's going to get interpreted as the command pip install pytest, which is being redirected with the > shell operator to a file named =2.7.3 --upgrade or so.

  27. bmorris3 commented on Apr 5, 2016

    @bmorris3

    @dstufft I wondered that myself in this commit, but it failed the tests similarly.

  28. added a commit that references this issue on Jan 5, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    type: bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions