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

Support for Python 3.9 #15

Closed
tirkarthi opened this issue Sep 22, 2020 · 16 comments
Closed

Support for Python 3.9 #15

tirkarthi opened this issue Sep 22, 2020 · 16 comments

Comments

@tirkarthi
Copy link
Contributor

The plugin seems to have a manual check for Python versions that it supports. 3.9 is to be released soon. Nose has problems related to importing ABC from collections directly nose-devs/nose#1099 . This change was postponed to 3.10 but might cause more people to migrate to pytest.

Also note that lib2to3 is deprecated since Python 3.10.

nose2pytest/script.py:21
  /root/checked_repos/nose2pytest/nose2pytest/script.py:21: PendingDeprecationWarning: lib2to3 package is deprecated and may not be able to parse Python 3.10+
    from lib2to3 import refactor, fixer_base, pygram, pytree, pgen2
python -m pytest -p no:relaxed
========================================================================= test session starts ==========================================================================
platform linux -- Python 3.9.0b5, pytest-6.0.2, py-1.9.0, pluggy-0.12.0
rootdir: /root/checked_repos/nose2pytest
plugins: hypothesis-4.43.1, xdist-1.28.0, forked-1.3.0, cov-2.8.1
collected 0 items / 1 error                                                                                                                                            

================================================================================ ERRORS ================================================================================
________________________________________________________________ ERROR collecting tests/test_script.py _________________________________________________________________
tests/test_script.py:8: in <module>
    from nose2pytest.script import NoseConversionRefactoringTool
nose2pytest/script.py:115: in <module>
    raise RuntimeError('nose2pytest must be run using Python in [3.4, 3.5, 3.6, 3.7, 3.8]')
E   RuntimeError: nose2pytest must be run using Python in [3.4, 3.5, 3.6, 3.7, 3.8]
=========================================================================== warnings summary ===========================================================================
nose2pytest/script.py:21
  /root/checked_repos/nose2pytest/nose2pytest/script.py:21: PendingDeprecationWarning: lib2to3 package is deprecated and may not be able to parse Python 3.10+
    from lib2to3 import refactor, fixer_base, pygram, pytree, pgen2

-- Docs: https://docs.pytest.org/en/stable/warnings.html
======================================================================= short test summary info ========================================================================
ERROR tests/test_script.py - RuntimeError: nose2pytest must be run using Python in [3.4, 3.5, 3.6, 3.7, 3.8]
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Interrupted: 1 error during collection !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
===================================================================== 1 warning, 1 error in 0.40s ======================================================================

Enabling 3.9 in the conditional gives me below errors :

python -m pytest -p no:relaxed
========================================================================= test session starts ==========================================================================
platform linux -- Python 3.9.0b5, pytest-6.0.2, py-1.9.0, pluggy-0.12.0
rootdir: /root/checked_repos/nose2pytest
plugins: hypothesis-4.43.1, xdist-1.28.0, forked-1.3.0, cov-2.8.1
collected 16 items                                                                                                                                                     

tests/test_script.py ......F...F..FFF                                                                                                                            [100%]

=============================================================================== FAILURES ===============================================================================
______________________________________________________________________ Test2Args.test_add_parens _______________________________________________________________________

self = <test_script.Test2Args object at 0x7fe587817790>

    def test_add_parens(self):
        check_transformation('assert_in(a == b, d)',
                             'assert (a == b) in d')
        check_transformation('assert_in(a != b, d)',
                             'assert (a != b) in d')
        check_transformation('assert_in(b <= c, d)',
                             'assert (b <= c) in d')
        check_transformation('assert_in(c >= d, d)',
                             'assert (c >= d) in d')
        check_transformation('assert_in(d < e, d)',
                             'assert (d < e) in d')
        check_transformation('assert_in(d > e, d)',
                             'assert (d > e) in d')
        check_transformation('assert_equal(a in b, c)',
                             'assert (a in b) == c')
        check_transformation('assert_equal(a not in b, c)',
                             'assert (a not in b) == c')
        check_transformation('assert_equal(a is b, c)',
                             'assert (a is b) == c')
        check_transformation('assert_equal(a is not b, c)',
                             'assert (a is not b) == c')
>       check_transformation('assert_equal(not a, c)',
                             'assert (not a) == c')

tests/test_script.py:148: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

input = 'assert_equal(not a, c)', expect = 'assert (not a) == c'

    def check_transformation(input, expect):
        result = refac.refactor_string(dedent(input + '\n'), 'script')
>       assert dedent(expect + '\n') == str(result)
E       AssertionError: assert 'assert (not a) == c\n' == 'assert not a == c\n'
E         - assert not a == c
E         + assert (not a) == c
E         ?        +     +

tests/test_script.py:38: AssertionError
______________________________________________________________________ Test3Args.test_add_parens _______________________________________________________________________

self = <test_script.Test3Args object at 0x7fe5877ac1c0>

    def test_add_parens(self):
        check_transformation('assert_almost_equal(a + b, c, delta=d>e)', 'assert abs((a + b) - c) <= (d>e)')
        check_transformation('assert_almost_equal(a | b, c ^ d, delta=0.1)', 'assert abs((a | b) - (c ^ d)) <= 0.1')
        check_transformation('assert_almost_equal(a & b, c << d, delta=0.1)', 'assert abs((a & b) - (c << d)) <= 0.1')
>       check_transformation('assert_almost_equal(a or b, c >> d, delta=0.1)', 'assert abs((a or b) - (c >> d)) <= 0.1')

tests/test_script.py:288: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

input = 'assert_almost_equal(a or b, c >> d, delta=0.1)', expect = 'assert abs((a or b) - (c >> d)) <= 0.1'

    def check_transformation(input, expect):
        result = refac.refactor_string(dedent(input + '\n'), 'script')
>       assert dedent(expect + '\n') == str(result)
E       AssertionError: assert 'assert abs((... d)) <= 0.1\n' == 'assert abs(a... d)) <= 0.1\n'
E         - assert abs(a or b - (c >> d)) <= 0.1
E         + assert abs((a or b) - (c >> d)) <= 0.1
E         ?            +      +

tests/test_script.py:38: AssertionError
_____________________________________________________________________ TestAssertTools.test_almost ______________________________________________________________________

self = <test_script.TestAssertTools object at 0x7fe5877cc280>

    def test_almost(self):
>       from pytest import assert_almost_equal, assert_not_almost_equal
E       ImportError: cannot import name 'assert_almost_equal' from 'pytest' (/root/py39-venv/lib/python3.9/site-packages/pytest/__init__.py)

tests/test_script.py:322: ImportError
________________________________________________________________ TestAssertTools.test_dict_keys_subset _________________________________________________________________

self = <test_script.TestAssertTools object at 0x7fe5877cc460>

    def test_dict_keys_subset(self):
        dict1 = dict(a=1, b=2, c=3)
    
        # check keys are subset:
        dict2 = dict1.copy()
>       pytest.assert_dict_contains_subset(dict1, dict2)
E       AttributeError: module 'pytest' has no attribute 'assert_dict_contains_subset'

tests/test_script.py:336: AttributeError
_______________________________________________________________ TestAssertTools.test_dict_values_subset ________________________________________________________________

self = <test_script.TestAssertTools object at 0x7fe587748280>

    def test_dict_values_subset(self):
        dict1 = dict(a=1, b=2, c=3)
    
        # check keys are subset:
        dict2 = dict1.copy()
        dict2['d'] = 4
        dict2['a'] = 4
>       pytest.raises(AssertionError, pytest.assert_dict_contains_subset, dict1, dict2)
E       AttributeError: module 'pytest' has no attribute 'assert_dict_contains_subset'

tests/test_script.py:352: AttributeError
=========================================================================== warnings summary ===========================================================================
nose2pytest/script.py:21
  /root/checked_repos/nose2pytest/nose2pytest/script.py:21: PendingDeprecationWarning: lib2to3 package is deprecated and may not be able to parse Python 3.10+
    from lib2to3 import refactor, fixer_base, pygram, pytree, pgen2

tests/test_script.py::Test1Arg::test_params
  /root/py39-venv/lib/python3.9/site-packages/nose/importer.py:12: DeprecationWarning: the imp module is deprecated in favour of importlib; see the module's documentation for alternative uses
    from imp import find_module, load_module, acquire_lock, release_lock

tests/test_script.py::Test1Arg::test_same_results
tests/test_script.py::Test2Args::test_same_results
tests/test_script.py::Test2Args::test_same_results
  <string>:1: SyntaxWarning: "is" with a literal. Did you mean "=="?

tests/test_script.py::Test1Arg::test_same_results
tests/test_script.py::Test2Args::test_same_results
tests/test_script.py::Test2Args::test_same_results
  <string>:1: SyntaxWarning: "is not" with a literal. Did you mean "!="?

tests/test_script.py::Test2Args::test_same_results
tests/test_script.py::Test2Args::test_same_results
  <string>:1: DeprecationWarning: Please use assertEqual instead.

tests/test_script.py::Test2Args::test_same_results
tests/test_script.py::Test2Args::test_same_results
  <string>:1: DeprecationWarning: Please use assertNotEqual instead.

tests/test_script.py::Test3Args::test_almost_equal
tests/test_script.py::Test3Args::test_almost_equal
tests/test_script.py::Test3Args::test_almost_equal
tests/test_script.py::Test3Args::test_almost_equal
  <string>:1: DeprecationWarning: Please use assertAlmostEqual instead.

tests/test_script.py::Test3Args::test_almost_equal
tests/test_script.py::Test3Args::test_almost_equal
tests/test_script.py::Test3Args::test_almost_equal
tests/test_script.py::Test3Args::test_almost_equal
  <string>:1: DeprecationWarning: Please use assertNotAlmostEqual instead.

-- Docs: https://docs.pytest.org/en/stable/warnings.html
======================================================================= short test summary info ========================================================================
FAILED tests/test_script.py::Test2Args::test_add_parens - AssertionError: assert 'assert (not a) == c\n' == 'assert not a == c\n'
FAILED tests/test_script.py::Test3Args::test_add_parens - AssertionError: assert 'assert abs((... d)) <= 0.1\n' == 'assert abs(a... d)) <= 0.1\n'
FAILED tests/test_script.py::TestAssertTools::test_almost - ImportError: cannot import name 'assert_almost_equal' from 'pytest' (/root/py39-venv/lib/python3.9/site-p...
FAILED tests/test_script.py::TestAssertTools::test_dict_keys_subset - AttributeError: module 'pytest' has no attribute 'assert_dict_contains_subset'
FAILED tests/test_script.py::TestAssertTools::test_dict_values_subset - AttributeError: module 'pytest' has no attribute 'assert_dict_contains_subset'
============================================================== 5 failed, 11 passed, 20 warnings in 0.62s ===============================================================
@PhilippSelenium
Copy link
Contributor

I also get these errors:

FAILED tests/test_script.py::Test2Args::test_add_parens - AssertionError: assert 'assert (not a) == c\n' == 'assert not a == c\n'
FAILED tests/test_script.py::Test3Args::test_add_parens - AssertionError: assert 'assert abs((... d)) <= 0.1\n' == 'assert abs(a... d)) <= 0.1\n'

for python 3.7 and 3.8

@jayvdb
Copy link
Contributor

jayvdb commented Nov 14, 2020

Regarding those errors mentioned by @PhilippSelenium , there is a bit of semi-related discussion at 850e40f#r44152239

Note in both cases it is the presentation of the assertion error which is different. That has no effect on whether nose2pytest is working correctly, and is very likely dependent on the pytest version being used in testing. Building the tests to support lots of pytest versions would be quite useful, and that would be a good reason to use tox in travis (actually tox-travis)

@jayvdb
Copy link
Contributor

jayvdb commented Nov 14, 2020

Running pytest with --assert=plain might help getting the tests working with more pytest versions

@PhilippSelenium
Copy link
Contributor

I get the same errors when running with --assert=plain

@nicoddemus
Copy link
Member

Note that this also applies to Python 3.10 (#21).

We are looking for volunteers to look into this issue.

@schollii
Copy link
Collaborator

I have fixed this: now works up to Python 3.11.

@Ghalko
Copy link

Ghalko commented Apr 5, 2023

This was not pushed to pypi, @nicoddemus @schollii

@nicoddemus
Copy link
Member

I'm afraid I don't have release right on PyPI.

@schollii could you please add me as maintainer on PyPI? Then we can setup a deploy workflow to streamline releases.

@schollii
Copy link
Collaborator

@nicoddemus done but please let me know before pushing updates to pypi

@nicoddemus
Copy link
Member

nicoddemus commented Apr 10, 2023

No problem.

I plan to add a deploy workflow like this one, and use the same release process, so every release should be made from a PR and have at least another approval. Is that sufficient you think?

@schollii
Copy link
Collaborator

Yes that works

@jaraco
Copy link

jaraco commented Aug 27, 2023

I tried to use this project today and it failed with an error:

@ nose2pytest --help
Traceback (most recent call last):
  File "/Users/jaraco/.local/bin/nose2pytest", line 5, in <module>
    from nose2pytest.script import main
  File "/Users/jaraco/.local/pipx/venvs/nose2pytest/lib/python3.11/site-packages/nose2pytest/script.py", line 115, in <module>
    raise RuntimeError('nose2pytest must be run using Python in [3.4, 3.5, 3.6]')
RuntimeError: nose2pytest must be run using Python in [3.4, 3.5, 3.6]

Are there any plans to release a version that runs on a supported Python version?

@schollii
Copy link
Collaborator

@jaraco which nose2pytest release/commit did you try? Latest (as of Nov 2022) works up to python 3.11.

@jaraco
Copy link

jaraco commented Aug 27, 2023

1.0.8:

 excuses main @ pipx install --force nose2pytest
  installed package nose2pytest 1.0.8, installed using Python 3.11.5
  These apps are now globally available
    - nose2pytest
done! ✨ 🌟 ✨
 excuses main @ nose2pytest --help
Traceback (most recent call last):
  File "/Users/jaraco/.local/bin/nose2pytest", line 5, in <module>
    from nose2pytest.script import main
  File "/Users/jaraco/.local/pipx/venvs/nose2pytest/lib/python3.11/site-packages/nose2pytest/script.py", line 115, in <module>
    raise RuntimeError('nose2pytest must be run using Python in [3.4, 3.5, 3.6]')
RuntimeError: nose2pytest must be run using Python in [3.4, 3.5, 3.6]

That's the latest version on PyPI:

image

I was able to work around the issue by installing from Github instead of PyPI, but in my experience, PyPI is the canonical place to publish releases. It's also where the readme directs the user for installation.

@schollii
Copy link
Collaborator

schollii commented Aug 27, 2023

@jaraco thanks and I agree we need to fix this.

@nicoddemus any update on creating that workflow? Looks like there should have been a 1.0.9 release or such.

@cclauss
Copy link
Contributor

cclauss commented Jan 17, 2024

% pipx install git+https://github.com/pytest-dev/nose2pytest.git

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants