Coder Social home page Coder Social logo

tox-venv's Introduction

tox-venv

Note the project has been deprecated as of 2020 May the 1st. virtualenv now creates venv style environments out of box, so this plugin is no longer needed.

https://travis-ci.org/tox-dev/tox-venv.svg?branch=master https://ci.appveyor.com/api/projects/status/fak35ur9yibmn0ly?svg=true

What is tox-venv?

tox-venv is a plugin that uses Python 3's builtin venv module for creating test environments instead of creating them with the virtualenv package. For Python versions that do not include venv (namely 3.2 and earlier), this package does nothing and reverts to tox's default implementation.

Why use tox-venv?

tox-venv was originally created because of compatibility issues between modern versions of Python and an aging virtualenv. Since then, virtualenv has undergone a major rewrite, and tox-venv has largely been made unnecessary. However, there may be cases where it's preferable to create test environments directly with the venv module, in which case you should use tox-venv.

Installation & Usage

To use tox-venv, install it alongside tox in your environment. Then, run tox as normal - no configuration necessary.

$ pip install tox tox-venv
$ tox

If you have already ran tox, it's necessary to recreate the test envs. Either run tox --recreate, or delete the .tox directory.

Compatibility

tox-venv is compatible with both Python 2 and 3, however it only creates test environments in Python 3.3 and later. Python 3.3 environments are only partially compatible, as not all options (such as --copies/--symlinks) were supported. Environments for Python 3.4 and later are fully compatible.

Release process

  • Update changelog
  • Update package version in setup.py
  • Create git tag for version
  • Upload release to PyPI
$ pip install -U twine setuptools wheel
$ rm -rf dist/ build/
# python setup.py sdist bdist_wheel
$ twine upload dist/*

tox-venv's People

Contributors

gaborbernat avatar obestwalter avatar rpkilby avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

tox-venv's Issues

running tests with current tox 3.1.2 show failures

Running the tests for tox-venv fails when the latest available tox from PyPI (3.1.2) is installed.
The setup.py install_requires only has a minimum version specifier tox>=2.0, maybe it should also have a upper bound.
In any case, the updated tests from upstream tox repository should be copied over here.
@rpkilby do you have an automated way to do this, or you just copy/paste and commit?

test_result_json failing with tox 3.8.3

Using the latest master, one test fails for me on my macOS 10.14.3 workstation:

tox-venv master $ tox                                                                                                                                                          
GLOB sdist-make: /Users/jaraco/code/public/tox-venv/setup.py
python create: /Users/jaraco/code/public/tox-venv/.tox/python
python installdeps: tox[testing]>=3.8.1
python inst: /Users/jaraco/code/public/tox-venv/.tox/.tmp/package/1/tox-venv-0.4.0.zip
python installed: apipkg==1.5,atomicwrites==1.3.0,attrs==19.1.0,coverage==4.5.3,execnet==1.5.0,filelock==3.0.10,freezegun==0.3.11,more-itertools==7.0.0,pathlib2==2.3.3,pluggy==0.9.0,psutil==5.6.1,py==1.8.0,pytest==4.3.1,pytest-cov==2.6.1,pytest-forked==1.0.2,pytest-mock==1.10.2,pytest-randomly==1.2.3,pytest-timeout==1.3.3,pytest-xdist==1.27.0,python-dateutil==2.8.0,six==1.12.0,toml==0.10.0,tox==3.8.3,tox-venv==0.4.0,virtualenv==16.4.3
python run-test-pre: PYTHONHASHSEED='2409559960'
python runtests: commands[0] | pytest tests
============================================================================= test session starts =============================================================================
platform darwin -- Python 3.7.3, pytest-4.3.1, py-1.8.0, pluggy-0.9.0
cachedir: .tox/python/.pytest_cache
Using --randomly-seed=1553876083
tox comes from: '/Users/jaraco/code/public/tox-venv/.tox/python/lib/python3.7/site-packages/tox/__init__.py'
rootdir: /Users/jaraco/code/public/tox-venv, inifile:
plugins: xdist-1.27.0, timeout-1.3.3, randomly-1.2.3, mock-1.10.2, forked-1.0.2, cov-2.6.1
collected 112 items                                                                                                                                                           

tests/test_z_cmdline.py .................F.....................................                                                                                         [ 49%]
tests/test_venv.py .........................................................                                                                                            [100%]

================================================================================== FAILURES ===================================================================================
______________________________________________________________________________ test_result_json _______________________________________________________________________________

cmd = <function cmd.<locals>.run at 0x1100801e0>, initproj = <function initproj.<locals>.initproj_ at 0x11004c0d0>
example123 = local('/private/var/folders/c6/v7hnmq453xb6p2dbz1gqc6rr0000gn/T/pytest-of-jaraco/pytest-1/test_result_json0/example123')

    def test_result_json(cmd, initproj, example123):
        cwd = initproj(
            "example123",
            filedefs={
                "tox.ini": """
                [testenv]
                deps = setuptools
                commands_pre = python -c 'print("START")'
                commands = python -c 'print("OK")'
                           - python -c 'raise SystemExit(1)'
                           python -c 'raise SystemExit(2)'
                           python -c 'print("SHOULD NOT HAPPEN")'
                commands_post = python -c 'print("END")'
            """
            },
        )
        json_path = cwd / "res.json"
        result = cmd("--result-json", json_path)
        result.assert_fail()
        data = json.loads(json_path.read_text(encoding="utf-8"))
    
        assert data["reportversion"] == "1"
        assert data["toxversion"] == tox.__version__
    
        for env_data in data["testenvs"].values():
            for command_type in ("setup", "test"):
                if command_type not in env_data:
                    assert False, "missing {}".format(command_type)
                for command in env_data[command_type]:
                    assert isinstance(command["command"], list)
>                   assert command["output"]
E                   AssertionError: assert ''

/Users/jaraco/code/public/tox-venv/tests/test_z_cmdline.py:493: AssertionError
=================================================================== 1 failed, 111 passed in 160.28 seconds ====================================================================
ERROR: InvocationError for command '/Users/jaraco/code/public/tox-venv/.tox/python/bin/pytest tests' (exited with code 1)
___________________________________________________________________________________ summary ___________________________________________________________________________________
ERROR:   python: commands failed

That was with tox 3.7.0. For good measure, I upgraded the tox in my local environment to 3.8.3 and now tests fail to run at all:

tox-venv master $ tox -r                                                                                                                                                       
GLOB sdist-make: /Users/jaraco/code/public/tox-venv/setup.py
python recreate: /Users/jaraco/code/public/tox-venv/.tox/python
___________________________________________________________________________________ summary ___________________________________________________________________________________
  python: commands succeeded
  congratulations :)
Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.7/bin/tox", line 10, in <module>
    sys.exit(cmdline())
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/tox/session/__init__.py", line 43, in cmdline
    main(args)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/tox/session/__init__.py", line 68, in main
    exit_code = session.runcommand()
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/tox/session/__init__.py", line 192, in runcommand
    return self.subcommand_test()
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/tox/session/__init__.py", line 220, in subcommand_test
    run_sequential(self.config, self.venv_dict)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/tox/session/commands/run/sequential.py", line 9, in run_sequential
    if venv.setupenv():
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/tox/venv.py", line 584, in setupenv
    status = self.update(action=action)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/tox/venv.py", line 242, in update
    self.hook.tox_testenv_create(action=action, venv=self)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pluggy/__init__.py", line 617, in __call__
    return self._hookexec(self, self._nonwrappers + self._wrappers, kwargs)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pluggy/__init__.py", line 222, in _hookexec
    return self._inner_hookexec(hook, methods, kwargs)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pluggy/__init__.py", line 216, in <lambda>
    firstresult=hook.spec_opts.get('firstresult'),
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pluggy/callers.py", line 201, in _multicall
    return outcome.get_result()
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pluggy/callers.py", line 76, in get_result
    raise ex[1].with_traceback(ex[2])
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pluggy/callers.py", line 180, in _multicall
    res = hook_impl.function(*args)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/tox_venv/hooks.py", line 102, in tox_testenv_create
    venv.session.make_emptydir(venv.path)
AttributeError: 'VirtualEnv' object has no attribute 'session'
tox-venv master $                                                          

Plans for project

Considering virtualenv now creates venv environments, should we deprecate and freeze this project?

Expected PyPy, got CPython

Attempting to run tox with PyPy ends up with CPython.

jaraco.itertools master $ tox -e pypy3                                                                                                                                    
pypy3 create: /Users/jaraco/code/main/jaraco.itertools/.tox/pypy3
pypy3: pip_version is pip
pypy3 installdeps: setuptools>=31.0.1
pypy3 develop-inst: /Users/jaraco/code/main/jaraco.itertools
pypy3 installed: appdirs==1.4.3,argcomplete==1.11.1,attrs==19.3.0,black==19.10b0,certifi==2019.11.28,click==7.1.1,coverage==5.1,docutils==0.16,entrypoints==0.3,flake8==3.7.9,importlib-metadata==1.6.0,inflect==4.1.0,-e git+gh://jaraco/jaraco.itertools@3720135f87aeb52b755c50cda9b1a43d42e7fdb7#egg=jaraco.itertools,mccabe==0.6.1,more-itertools==8.2.0,packaging==20.3,pathspec==0.8.0,pip-run==5.3,pipx==0.15.1.3,pluggy==0.13.1,py==1.8.1,pycodestyle==2.5.0,pyflakes==2.1.1,pyparsing==2.4.6,pytest==5.4.1,pytest-black==0.3.8,pytest-black-multipy==1.0.0,pytest-checkdocs==1.2.3,pytest-cov==2.8.1,pytest-flake8==1.0.5,regex==2020.4.4,six==1.14.0,toml==0.10.0,typed-ast==1.4.1,userpath==1.3.0,wcwidth==0.1.9,zipp==3.1.0
pypy3 run-test-pre: PYTHONHASHSEED='2250303190'
pypy3 run-test: commands[0] | pytest
========================================================================== test session starts ===========================================================================
platform darwin -- Python 3.8.2, pytest-5.4.1, py-1.8.1, pluggy-0.13.1
...

Uninstalling tox-venv, PyPy is used.

virtualenv still being invoked (Windows)

I've installed tox-venv in my environment:

PS C:\Users\jaraco\m\jaraco.windows> py --version
Python 3.6.4
PS C:\Users\jaraco\m\jaraco.windows> py -m pip freeze
pluggy==0.6.0
py==1.5.2
six==1.11.0
tox==2.9.1
tox-venv==0.1.0
virtualenv==15.1.0

Yet, when I run tox, it fails invoking virtualenv (with the error reported in tox-dev/tox#721).

How can I determine why tox-venv is not causing use of tox-venv?

Error in TestCreationConfig.test_matchingdependencies_latest

Running tox on e740a96 of tox-venv, I see this following error:

__________________________________________________________ TestCreationConfig.test_matchingdependencies_latest ___________________________________________________________

self = <test_venv.TestCreationConfig object at 0x10926abe0>, newconfig = <function create_new_config_file.<locals>.create_new_config_file_ at 0x1092c55e0>
mocksession = <tox._pytestplugin.create_mocksession.<locals>.MockSession object at 0x1094fd250>

    def test_matchingdependencies_latest(self, newconfig, mocksession):
        config = newconfig(
            [],
            """
            [tox]
            distshare={toxworkdir}/distshare
            [testenv]
            deps={distshare}/xyz-*
        """,
        )
        config.distshare.ensure("xyz-1.2.0.zip")
        xyz2 = config.distshare.ensure("xyz-1.2.1.zip")
        mocksession.new_config(config)
        venv = mocksession.getvenv("python")
        cconfig = venv._getliveconfig()
        md5, path = cconfig.deps[0]
        assert path == xyz2
>       assert md5 == path.computehash()
E       AssertionError: assert 'e3b0c44298fc...5991b7852b855' == 'd41d8cd98f00...00998ecf8427e'
E         - e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855
E         + d41d8cd98f00b204e9800998ecf8427e

tests/test_venv.py:548: AssertionError

[BUG] 3.8.0 breaks tox-venv / pip's CI (AttributeError: 'VirtualEnv' object has no attribute 'session')

PR #1145 (released as part of 3.8.0) seems to be breaking tox-venv because the PR removed the session attribute of VirtualEnv, which tox-venv uses.

Here is the traceback from pip's CI:

  File "/home/travis/virtualenv/python3.6.7/bin/tox", line 11, in <module>
    sys.exit(cmdline())
  File "/home/travis/virtualenv/python3.6.7/lib/python3.6/site-packages/tox/session/__init__.py", line 42, in cmdline
    main(args)
  File "/home/travis/virtualenv/python3.6.7/lib/python3.6/site-packages/tox/session/__init__.py", line 63, in main
    retcode = session.runcommand()
  File "/home/travis/virtualenv/python3.6.7/lib/python3.6/site-packages/tox/session/__init__.py", line 187, in runcommand
    return self.subcommand_test()
  File "/home/travis/virtualenv/python3.6.7/lib/python3.6/site-packages/tox/session/__init__.py", line 215, in subcommand_test
    run_sequential(self.config, self.venv_dict)
  File "/home/travis/virtualenv/python3.6.7/lib/python3.6/site-packages/tox/session/commands/run/sequential.py", line 9, in run_sequential
    if venv.setupenv():
  File "/home/travis/virtualenv/python3.6.7/lib/python3.6/site-packages/tox/venv.py", line 582, in setupenv
    status = self.update(action=action)
  File "/home/travis/virtualenv/python3.6.7/lib/python3.6/site-packages/tox/venv.py", line 240, in update
    self.hook.tox_testenv_create(action=action, venv=self)
  File "/home/travis/virtualenv/python3.6.7/lib/python3.6/site-packages/pluggy/hooks.py", line 284, in __call__
    return self._hookexec(self, self.get_hookimpls(), kwargs)
  File "/home/travis/virtualenv/python3.6.7/lib/python3.6/site-packages/pluggy/manager.py", line 67, in _hookexec
    return self._inner_hookexec(hook, methods, kwargs)
  File "/home/travis/virtualenv/python3.6.7/lib/python3.6/site-packages/pluggy/manager.py", line 61, in <lambda>
    firstresult=hook.spec.opts.get("firstresult") if hook.spec else False,
  File "/home/travis/virtualenv/python3.6.7/lib/python3.6/site-packages/pluggy/callers.py", line 208, in _multicall
    return outcome.get_result()
  File "/home/travis/virtualenv/python3.6.7/lib/python3.6/site-packages/pluggy/callers.py", line 80, in get_result
    raise ex[1].with_traceback(ex[2])
  File "/home/travis/virtualenv/python3.6.7/lib/python3.6/site-packages/pluggy/callers.py", line 187, in _multicall
    res = hook_impl.function(*args)
  File "/home/travis/virtualenv/python3.6.7/lib/python3.6/site-packages/tox_venv/hooks.py", line 99, in tox_testenv_create
    venv.session.make_emptydir(venv.path)
AttributeError: 'VirtualEnv' object has no attribute 'session'

And here is the relevant tox-venv code:

venv.session.make_emptydir(venv.path)

venv results in older Setuptools

By installing tox-venv, I've started getting bugs in my tests (namely pypa/setuptools#885) because an older Setuptools is installed by venv than is installed by virtualenv (28.8.0 vs. latest).

I'm reporting this behavior here so it can be considered, as I know this library is being considered for default inclusion in tox, so this change will have unintended side effects for users.

I've found if I include setuptools >= 31.0.1 in my deps, it will roughly restore the behavior I was seeing before.

Thank you! (Not an issue)

Hi, I just wanted to let you know, that your plugin safed us unnecessary trouble today. We have some old test servers chugging along on Python 3.4 and all of a sudden tox got stuck in the create stage somewhere in the depth of virtualenv. After some fruitless investigation, we decided to use venv instead, typed pip install tox-venv, problem solved :)

Broken on macOS with Python 3.6 and below

On Python 3.4 and 3.5 on macOS (at least), venv is no longer viable and pip is broken:

draft $ .env/bin/python -m pip install -U pip
Cache entry deserialization failed, entry ignored
Could not fetch URL https://pypi.python.org/simple/pip/: There was a problem confirming the ssl certificate: [SSL: TLSV1_ALERT_PROTOCOL_VERSION] tlsv1 alert protocol version (_ssl.c:645) - skipping
Requirement already up-to-date: pip in ./.env/lib/python3.5/site-packages

As a result, this means that tox-venv also is broken on those Pythons.

The only solution I've found is to use an external tool like cUrl or httpie to download and install a newer pip (9.0.3 or later and maybe 10 is required, IIUC).

hookimpl should be fetched via pluggy - not import

I am doing some refactoring in core and the importable hookimpl will go away. While this works it is not clean doing this and actually tox does not really need to expose a hookimpl object, so this will go away in tox after a deprecation phase.

https://github.com/tox-dev/tox-venv/blob/master/src/tox_venv/hooks.py#L5

should be replaced by using the pluggy API

import pluggy
hookimpl = pluggy.HookImplMarker("tox")

see: https://pluggy.readthedocs.io/en/latest/api_reference.html?highlight=hookimplmarker#pluggy.HookimplMarker

upgrade pip/setuptools and install wheel in venv?

when using the regular tox (without tox-venv plugin), the created environments will have the latest versions of pip and setuptools, because the default behaviour of virtualenv is to reach out to the Internet to download the latest versions from PyPI, unless --no-download is passed (which tox doesn't seem to be doing). In addition, virtualenv always installs the wheel module as well as pip and setuptools.

However, when using the built-in python3's venv module, pip and setuptools gets installed using the ensurepip built-in module, which by design does not access the Internet. Also, wheel doesn't get automatically installed when doing ensurepip.

For consistency between the tox environments for python2.7 and those for python3+, it would be great if tox-venv plugin would do a python -m pip install --upgrade pip setuptools wheel after having created the new venv.

Thanks!

Broken environments result when venv is used and default pip is old

In pypa/setuptools#2000, I discovered an emergent issue where because the default pip for venv is 9.0.1 and because tox-pip-version isn't yet installed, the bootstrap environment (.tox/.tox; is there a better name for it?) gets installed improperly because one of the dependencies (zipp) has a requirement to be installed as a wheel (which doesn't happen on PyPy) or with pip 10 or later or with setuptools 42 or later. As far as I can tell, there's no way to ensure that pip is upgraded in the bootstrap environment before installing the bootstrap requirements. Even having tox-pip-version installed in advance does not work around the issue. This dockerfile replicates the issue:

FROM ubuntu:xenial

RUN apt update
RUN apt install -y curl libexpat1 bzip2
RUN curl -sSf --retry 5 https://storage.googleapis.com/travis-ci-language-archives/python/binaries/ubuntu/16.04/x86_64/pypy3.tar.bz2 -o - | tar xj --directory /
ENV PATH="/opt/python/pypy3/bin:${PATH}"

RUN python -m pip install -U pip setuptools wheel
RUN python -m pip install -U tox tox-venv tox-pip-version

RUN echo '[tox]\n\
skipsdist = true\n\
requires = \n\
  requests\n\
\n\
[testenv]\n\
pip_version = pip\n\
' > tox.ini

CMD tox

Here's the output:

draft $ docker run -it $(docker build -q .)
.tox create: //.tox/.tox
.tox installdeps: requests, tox >= 3.14.4
Traceback (most recent call last):
  File "/opt/python/pypy3/lib-python/3/runpy.py", line 183, in _run_module_as_main
    mod_name, mod_spec, code = _get_module_details(mod_name, _Error)
  File "/opt/python/pypy3/lib-python/3/runpy.py", line 142, in _get_module_details
    return _get_module_details(pkg_main_name, error)
  File "/opt/python/pypy3/lib-python/3/runpy.py", line 109, in _get_module_details
    __import__(pkg_name)
  File "//.tox/.tox/site-packages/tox/__init__.py", line 9, in <module>
    import pluggy
  File "//.tox/.tox/site-packages/pluggy/__init__.py", line 16, in <module>
    from .manager import PluginManager, PluginValidationError
  File "//.tox/.tox/site-packages/pluggy/manager.py", line 11, in <module>
    import importlib_metadata
  File "//.tox/.tox/site-packages/importlib_metadata/__init__.py", line 9, in <module>
    import zipp
ModuleNotFoundError: No module named 'zipp'

Improve executable path detection

Improve unix python3 detection. Right now, it's assumed that there is a python3 binary in the bin directory. This isn't necessarily the case, such as when pyenv is misconfigured.

How is this package to be used?

The purpose of this package sounds interesting, but how is it to be used?
Has it to be installed in the same virtualenv as tox?
Has it to be configured in tox.ini?

Sorry for not knowing this and not finding the appropriate documentation.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.