diff --git a/azure-pipelines.yml b/azure-pipelines.yml index c87d0b57b..803a210ef 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -35,6 +35,10 @@ jobs: image: [linux, windows, macOs] py27: image: [linux, windows, macOs] + pypy: + image: [linux] + pypy3: + image: [linux] py36: image: [linux, windows, macOs] py35: diff --git a/docs/changelog/1378.bugfix.rst b/docs/changelog/1378.bugfix.rst new file mode 100644 index 000000000..f4ac64819 --- /dev/null +++ b/docs/changelog/1378.bugfix.rst @@ -0,0 +1 @@ +Fix ``current_tox_py`` for ``pypy`` / ``pypy3`` - by :user:`asottile` diff --git a/src/tox/_pytestplugin.py b/src/tox/_pytestplugin.py index 7637880ff..1ff89155f 100644 --- a/src/tox/_pytestplugin.py +++ b/src/tox/_pytestplugin.py @@ -577,7 +577,7 @@ def build_session(config): def current_tox_py(): """generate the current (test runners) python versions key e.g. py37 when running under Python 3.7""" - return "py{}".format("".join(str(i) for i in sys.version_info[0:2])) + return "{}{}{}".format("pypy" if tox.INFO.IS_PYPY else "py", *sys.version_info) def pytest_runtest_setup(item): diff --git a/tests/integration/test_package_int.py b/tests/integration/test_package_int.py index b91848520..a982c2a07 100644 --- a/tests/integration/test_package_int.py +++ b/tests/integration/test_package_int.py @@ -14,17 +14,19 @@ def test_package_setuptools(initproj, cmd): initproj( "magic-0.1", filedefs={ - "tox.ini": """ - [tox] - isolated_build = true - [testenv:.package] - basepython = python - """, - "pyproject.toml": """ - [build-system] - requires = ["setuptools >= 35.0.2", "setuptools_scm >= 2.0.0, <3"] - build-backend = "setuptools.build_meta" - """, + "tox.ini": """\ + [tox] + isolated_build = true + [testenv:.package] + basepython = {} + """.format( + sys.executable + ), + "pyproject.toml": """\ + [build-system] + requires = ["setuptools >= 35.0.2", "setuptools_scm >= 2.0.0, <3"] + build-backend = "setuptools.build_meta" + """, }, ) run(cmd, "magic-0.1.tar.gz") @@ -37,26 +39,28 @@ def test_package_flit(initproj, cmd): initproj( "magic-0.1", filedefs={ - "tox.ini": """ - [tox] - isolated_build = true - [testenv:.package] - basepython = python - """, - "pyproject.toml": """ - [build-system] - requires = ["flit"] - build-backend = "flit.buildapi" - - [tool.flit.metadata] - module = "magic" - author = "Happy Harry" - author-email = "happy@harry.com" - home-page = "https://github.com/happy-harry/is" - requires = [ - "tox", - ] - """, + "tox.ini": """\ + [tox] + isolated_build = true + [testenv:.package] + basepython = {} + """.format( + sys.executable + ), + "pyproject.toml": """\ + [build-system] + requires = ["flit"] + build-backend = "flit.buildapi" + + [tool.flit.metadata] + module = "magic" + author = "Happy Harry" + author-email = "happy@harry.com" + home-page = "https://github.com/happy-harry/is" + requires = [ + "tox", + ] + """, ".gitignore": ".tox", }, add_missing_setup_py=False, @@ -78,24 +82,25 @@ def test_package_poetry(initproj, cmd): initproj( "magic-0.1", filedefs={ - "tox.ini": """ - [tox] - isolated_build = true - [testenv:.package] - basepython = python - """, - "pyproject.toml": """ - [build-system] - requires = ["poetry>=0.12"] - build-backend = "poetry.masonry.api" - - [tool.poetry] - name = "magic" - version = "0.1.0" - description = "" - authors = ["Name "] - - """, + "tox.ini": """\ + [tox] + isolated_build = true + [testenv:.package] + basepython = {} + """.format( + sys.executable + ), + "pyproject.toml": """\ + [build-system] + requires = ["poetry>=0.12"] + build-backend = "poetry.masonry.api" + + [tool.poetry] + name = "magic" + version = "0.1.0" + description = "" + authors = ["Name "] + """, ".gitignore": ".tox", }, add_missing_setup_py=False, diff --git a/tests/unit/config/test_config.py b/tests/unit/config/test_config.py index 2f019b791..7893d012b 100644 --- a/tests/unit/config/test_config.py +++ b/tests/unit/config/test_config.py @@ -1909,17 +1909,21 @@ def test_default_factors(self, newconfig): def test_default_factors_conflict(self, newconfig, capsys): with pytest.warns(UserWarning, match=r"conflicting basepython .*"): + exe = "pypy3" if tox.INFO.IS_PYPY else "python3" + env = "pypy27" if tox.INFO.IS_PYPY else "py27" config = newconfig( - """ + """\ [testenv] - basepython=python3 - [testenv:py27] + basepython={} + [testenv:{}] commands = python --version - """ + """.format( + exe, env + ) ) assert len(config.envconfigs) == 1 - envconfig = config.envconfigs["py27"] - assert envconfig.basepython == "python3" + envconfig = config.envconfigs[env] + assert envconfig.basepython == exe def test_default_factors_conflict_lying_name( self, newconfig, capsys, tmpdir, recwarn, monkeypatch diff --git a/tests/unit/interpreters/test_interpreters.py b/tests/unit/interpreters/test_interpreters.py index ea6f65dff..cc2c3f58a 100644 --- a/tests/unit/interpreters/test_interpreters.py +++ b/tests/unit/interpreters/test_interpreters.py @@ -28,6 +28,7 @@ def create_interpreters_instance(): return Interpreters(hook=pm.hook) +@pytest.mark.skipif(tox.INFO.IS_PYPY, reason="testing cpython interpreter discovery") def test_tox_get_python_executable(): class envconfig: basepython = sys.executable diff --git a/tests/unit/test_venv.py b/tests/unit/test_venv.py index 05231121f..0e302709a 100644 --- a/tests/unit/test_venv.py +++ b/tests/unit/test_venv.py @@ -446,8 +446,8 @@ def test_install_command_not_installed_bash(newmocksession): def test_install_python3(newmocksession): - if not py.path.local.sysfind("python3"): - pytest.skip("needs python3") + if not py.path.local.sysfind("python3") or tox.INFO.IS_PYPY: + pytest.skip("needs cpython3") mocksession = newmocksession( [], """\ diff --git a/tests/unit/test_z_cmdline.py b/tests/unit/test_z_cmdline.py index ae74648aa..20e5d0ce5 100644 --- a/tests/unit/test_z_cmdline.py +++ b/tests/unit/test_z_cmdline.py @@ -784,11 +784,13 @@ def test_notest(initproj, cmd): initproj( "example123", filedefs={ - "tox.ini": """ - # content of: tox.ini - [testenv:py26] - basepython=python - """ + "tox.ini": """\ + # content of: tox.ini + [testenv:py26] + basepython={} + """.format( + sys.executable + ) }, ) result = cmd("-v", "--notest")