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

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

Closed
pytestbot opened this issue May 14, 2015 · 49 comments
Closed

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

pytestbot opened this issue May 14, 2015 · 49 comments
Labels
type: bug problem that needs to be addressed

Comments

@pytestbot
Copy link
Contributor

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).


@pytestbot
Copy link
Contributor Author

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.

@pytestbot
Copy link
Contributor Author

Original comment by BitBucket: gvanrossum, GitHub: gvanrossum:


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

@pytestbot
Copy link
Contributor Author

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.

@pytestbot
Copy link
Contributor Author

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!

@pytestbot
Copy link
Contributor Author

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 !

@pytestbot
Copy link
Contributor Author

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.

@pytestbot
Copy link
Contributor Author

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.

@pytestbot
Copy link
Contributor Author

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.

@warsaw
Copy link

warsaw commented Jun 19, 2015

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.

@warsaw
Copy link

warsaw commented Jun 23, 2015

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

@warsaw
Copy link

warsaw commented Jun 23, 2015

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

@jonathaneunice
Copy link

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.

@The-Compiler
Copy link
Member

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

@warsaw
Copy link

warsaw commented Jul 10, 2015

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.

@nicoddemus
Copy link
Member

There's some work being done in #801, and any help there is appreciated.

@nicoddemus
Copy link
Member

PR #801 is ready for merging, everybody is welcome to try it out!

@warsaw
Copy link

warsaw commented Jul 17, 2015

On Jul 16, 2015, at 05:53 PM, Bruno Oliveira wrote:

PR #801 is ready for merging, everybody is welcome to try it out!

I took the patch and applied it to the Debian package, uploading it to my
experimental Python 3.5 PPA. Then I rebuilt configobj and python-cffi without
the --assert=plain hack and both built successfully. I'd say this is good to
go. I'll probably upload a version of pytest containing this patch to Debian
unstable next, and will revert it when this fix is released by pytest
upstream.

Thanks for working on this! It will make Python 3.5 users lives much happier.

@The-Compiler
Copy link
Member

@warsaw - note I've heard plans about releasing 2.8 before EuroPython, and after 3.5 support is fixed. So this might happen very soon.

@nicoddemus I vaguely remember @hpk42 said you could do the release if you feel like - are you planning to do that? Anything missing? 😄

@nicoddemus
Copy link
Member

@The-Compiler

note I've heard plans about releasing 2.8 before EuroPython, and after 3.5 support is fixed. So this might happen very soon.

Holger mentioned that he would like to first vendor pluggy into pytest before releasing 2.8, I'm not sure how that work is progressing.

I vaguely remember @hpk42 said you could do the release if you feel like - are you planning to do that? Anything missing? 😄

We were talking about making a 2.7.3 bug-fix release soon (I would say in a week or so), which should also include the fix for this issue IMO. FWIW, all pytest core developers can now make a release. 😄

@flub
Copy link
Member

flub commented Jul 18, 2015

This is now merged to master, not on the pytest-2.7 branch though.

@nicoddemus
Copy link
Member

No problem, I will port it. Thanks @flub!

@nicoddemus
Copy link
Member

Strange, Travis is now failing on both master and pytest-2.7 with this problem:

$ python --version
Python 3.6.0a0
...
py35 create: /home/travis/build/pytest-dev/pytest/.tox/py35
ERROR: InterpreterNotFound: python3.5

Note that the python version for Travis' nightly build is now 3.6.0a0, which is different from the previous build of this branch that passed, Python 3.5.0a4+.

Does any one know if there's been any changes from Travis in the last two days?

CC @Carreau @takluyver

@Carreau
Copy link
Contributor

Carreau commented Jul 18, 2015

In the last week, probably as we did complain to travis that "nighly" was stuck on 3.5a, they probably updated too aggressively.

nippoo added a commit to nippoo/phy that referenced this issue Sep 15, 2015
nippoo added a commit to nippoo/phy that referenced this issue Sep 15, 2015
nippoo added a commit to nippoo/phy that referenced this issue Sep 15, 2015
@ByteCommander
Copy link

I'm sorry, but this whole issue became really big and confusing. I see that pytest is actively developed and that you guys are really trying to fix the Python 3.5 incompatibility soon, but is there any workaround available at the moment? I was not able to find one, but maybe I missed the right link? Thanks for replies.

@warsaw
Copy link

warsaw commented Sep 15, 2015

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

@The-Compiler
Copy link
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

@flub
Copy link
Member

flub commented Sep 16, 2015

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).

@warsaw
Copy link

warsaw commented Sep 16, 2015

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. :)

@Toilal
Copy link
Contributor

Toilal commented Sep 18, 2015

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

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

@bmorris3
Copy link

bmorris3 commented Apr 4, 2016

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

@Toilal
Copy link
Contributor

Toilal commented Apr 4, 2016

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)

@Toilal
Copy link
Contributor

Toilal commented Apr 4, 2016

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)

@The-Compiler
Copy link
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 😉

@bmorris3
Copy link

bmorris3 commented Apr 4, 2016

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.

@dstufft
Copy link

dstufft commented Apr 5, 2016

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.

@bmorris3
Copy link

bmorris3 commented Apr 5, 2016

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

Kuniwak added a commit to Vimjas/vint that referenced this issue Jan 5, 2018
Kuniwak added a commit to Vimjas/vint that referenced this issue Jun 18, 2018
* Reproduce the map() problem

* Fix test on Python 3.5+

pytest-dev/pytest#744

* First aid for false positives caused by map([], '""')

* Test nested map such as map([], 'map([], "v:val")')

* Make performance better (but not measured)

* Upgrade Vital.vim
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug problem that needs to be addressed
Projects
None yet
Development

No branches or pull requests