diff options
| author | André Caron <andre.l.caron@gmail.com> | 2017-06-30 12:19:29 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2017-06-30 12:19:29 -0400 |
| commit | 89848acb8137ef313cda5336edefe32048330392 (patch) | |
| tree | b22c79c2d8fce8697123fc1d7f30ccba3ccf8c25 | |
| parent | 10b0d6c12ce041b4fe588c194ac9d80d82bd8d98 (diff) | |
| parent | 6117a30068812bfce40f9b2e48f5587206e06e49 (diff) | |
| download | tox-git-89848acb8137ef313cda5336edefe32048330392.tar.gz | |
Merge branch 'master' into envsubs-independence
| -rw-r--r-- | CHANGELOG | 7 | ||||
| -rw-r--r-- | CONTRIBUTORS | 4 | ||||
| -rw-r--r-- | doc/config-v2.txt | 80 | ||||
| -rw-r--r-- | doc/config.txt | 6 | ||||
| -rw-r--r-- | doc/example/basic.txt | 9 | ||||
| -rw-r--r-- | doc/example/general.txt | 6 | ||||
| -rw-r--r-- | doc/example/jenkins.txt | 10 | ||||
| -rw-r--r-- | doc/example/platform.txt | 43 | ||||
| -rw-r--r-- | doc/example/pytest.txt | 24 | ||||
| -rw-r--r-- | doc/example/result.txt | 28 | ||||
| -rw-r--r-- | doc/examples.txt | 1 | ||||
| -rw-r--r-- | doc/index.txt | 6 | ||||
| -rw-r--r-- | doc/install.txt | 7 | ||||
| -rw-r--r-- | tests/test_config.py | 81 | ||||
| -rw-r--r-- | tests/test_quickstart.py | 31 | ||||
| -rw-r--r-- | tests/test_venv.py | 14 | ||||
| -rw-r--r-- | tests/test_z_cmdline.py | 10 | ||||
| -rw-r--r-- | tox.ini | 12 | ||||
| -rw-r--r-- | tox/__init__.py | 9 | ||||
| -rw-r--r-- | tox/_pytestplugin.py | 10 | ||||
| -rwxr-xr-x | tox/config.py | 4 | ||||
| -rw-r--r-- | tox/session.py | 4 |
22 files changed, 239 insertions, 167 deletions
@@ -1,7 +1,12 @@ Not released yet ----- +---------------- - #474: Start using setuptools_scm for tag based versioning. +- #484: Renamed `py.test` to `pytest` throughout the project +- #506: With `-a`: do not show additional environments header if there are none +- #517: Forward NUMBER_OF_PROCESSORS by default on Windows to fix + `multiprocessor.cpu_count()`. +- #518: Forward `USERPROFILE` by default on Windows. - #515: Don't require environment variables in test environments where they are not used. diff --git a/CONTRIBUTORS b/CONTRIBUTORS index 5f6bab94..1a163474 100644 --- a/CONTRIBUTORS +++ b/CONTRIBUTORS @@ -15,7 +15,7 @@ Philip Thiem Monty Taylor Bruno Oliveira Ionel Maries Cristian -Anatoly techntonik +anatoly techtonik Matt Jeffery Chris Jerdonek Ronald Evers @@ -23,6 +23,7 @@ Carl Meyer Anthon van der Neuth Matt Good Mattieu Agopian +Mikhail Kyshtymov Asmund Grammeltwedt Ionel Maries Cristian Julian Krause @@ -44,3 +45,4 @@ Josh Smeaton Paweł Adamczak Oliver Bestwalter Selim Belhaouane +Nick Douma diff --git a/doc/config-v2.txt b/doc/config-v2.txt index daa19e13..288586ab 100644 --- a/doc/config-v2.txt +++ b/doc/config-v2.txt @@ -2,19 +2,19 @@ V2: new tox multi-dimensional, platform-specific configuration -------------------------------------------------------------------- .. note:: - + This is a draft document sketching a to-be-done implementation. It does not fully specify each change yet but should give a good - idea of where things are heading. For feedback, mail the + idea of where things are heading. For feedback, mail the testing-in-python mailing list or open a pull request on https://github.com/tox-dev/tox/blob/master/doc/config-v2.txt **Abstract**: Adding multi-dimensional configuration, platform-specification and multiple installers to tox.ini. - + **Target audience**: Developers using or wanting to use tox for testing their python projects. - + Issues with current tox (1.4) configuration ------------------------------------------------ @@ -22,17 +22,17 @@ Tox is used as a tool for creating and managing virtualenv environments and running tests in them. As of tox-1.4 there are some issues frequently coming up with its configuration language: -- there is no way to instruct tox to parametrize testenv specifications +- there is no way to instruct tox to parametrize testenv specifications other than to list all combinations by specifying a ``[testenv:...]`` - section for each combination. Examples of real life situations + section for each combination. Examples of real life situations arising from this: * https://github.com/tomchristie/django-rest-framework/blob/b001a146d73348af18cfc4c943d87f2f389349c9/tox.ini - + * https://bitbucket.org/tabo/django-treebeard/src/93b579395a9c/tox.ini - there is no way to have platform specific settings other than to - define specific testenvs and invoke tox with a platform-specific + define specific testenvs and invoke tox with a platform-specific testenv list. - there is no way to specify the platforms against which a project @@ -50,29 +50,29 @@ Goals, resolving those issues This document discusses a possible solution for each of these issues, namely these goals: - -- allow to more easily define and run dependency/interpreter variants + +- allow to more easily define and run dependency/interpreter variants with testenvs - allow platform-specific settings - allow to specify platforms against which tests should run - allow to run installer-variants (easy_install or pip, xxx) - try to mimick/re-use bash-style syntax to ease learning curve. - + Example: Generating and selecting variants ---------------------------------------------- - + Suppose you want to test your package against python2.6, python2.7 and on the -windows and linux platforms. Today you would have to +windows and linux platforms. Today you would have to write down 2*2 = 4 ``[testenv:*]`` sections and then instruct tox to run a specific list of environments on each platform. - + With tox-1.X you can directlys specify combinations:: - + # combination syntax gives 2 * 2 = 4 testenv names # envlist = {py26,py27}-{win,linux} - + [testenv] deps = pytest platform = @@ -81,7 +81,7 @@ With tox-1.X you can directlys specify combinations:: basepython = py26: python2.6 py27: python2.7 - commands = py.test + commands = pytest Let's go through this step by step:: @@ -103,7 +103,7 @@ Our ``[testenv]`` uses a new templating style for the ``platform`` definition:: These two conditional settings will lead to either ``windows`` or ``linux`` as the platform string. When the test environment is run, -its platform string needs to be contained in the string returned +its platform string needs to be contained in the string returned from ``platform.platform()``. Otherwise the environment will be skipped. The next configuration item in the ``testenv`` section deals with @@ -118,7 +118,7 @@ appears in the environment name. The last config item is simply the invocation of the test runner:: - commands = py.test + commands = pytest Nothing special here :) @@ -129,25 +129,25 @@ Nothing special here :) [tox] envlist = {py26,py27}-{win,linux} - + [testenv] deps = pytest - commands = py.test + commands = pytest - Voila, this multi-dimensional ``tox.ini`` configuration + Voila, this multi-dimensional ``tox.ini`` configuration defines 2*2=4 environments. - + The new "platform" setting -------------------------------------- A testenv can define a new ``platform`` setting. If its value -is not contained in the string obtained from calling +is not contained in the string obtained from calling ``sys.platform`` the environment will be skipped. Expanding the ``envlist`` setting ---------------------------------------------------------- - + The new ``envlist`` setting allows to use ``{}`` bash-style expressions. XXX explanation or pointer to bash-docs @@ -159,7 +159,7 @@ start with "NAME: ..." will be checked for being part in the environment name. If they are part of it, the remainder will be the new line. If they are not part of it, the whole line will be left out. Parts of an environment name are obtained by ``-``-splitting it. - + Variant specification with [variant:VARNAME] Showing all expanded sections @@ -172,12 +172,12 @@ you can ask tox to show their expansion with a new option:: Making sure your packages installs with easy_install ------------------------------------------------------ - + The new "installer" testenv setting allows to specify the tool for installation in a given test environment:: - + [testenv] - installer = + installer = easy: easy_install pip: pip @@ -199,7 +199,7 @@ tox comes with predefined settings for certain variants, namely: pythonNN or PyPy interpreter * ``{win32,linux,darwin}`` defines the according ``platform``. -You can use those in your “envlist” specification +You can use those in your “envlist” specification without the need to define them yourself. @@ -211,7 +211,7 @@ tox leverages bash-style syntax if you specify mintoxversion = 1.4: - $VARNAME or ${...} syntax instead of the older {} substitution. - XXX go through config.txt and see how it would need to be changed - + Transforming the examples: django-rest ------------------------------------------------ @@ -219,10 +219,10 @@ The original `django-rest-framework tox.ini <https://github.com/tomchristie/django-rest-framework/blob/b001a146d73348af18cfc4c943d87f2f389349c9/tox.ini>`_ file has 159 lines and a lot of repetition, the new one would +have 20 lines and almost no repetition:: - + [tox] envlist = {py25,py26,py27}-{django12,django13}{,-example} - + [testenv] deps= coverage==3.4 @@ -236,18 +236,18 @@ lines and almost no repetition:: example: httplib2==0.6.0 example: Markdown==2.0.3 - commands = + commands = !example: python setup.py test example: python examples/runtests.py - + Note that ``{,-example}`` in the envlist denotes two values, an empty one and a ``example`` one. The empty value means that there are no specific -settings and thus no need to define a variant name. +settings and thus no need to define a variant name. Transforming the examples: django-treebeard ------------------------------------------------ - + Another `tox.ini <https://bitbucket.org/tabo/django-treebeard/raw/93b579395a9c/tox.ini>`_ has 233 lines and runs tests against multiple Postgres and Mysql @@ -256,7 +256,7 @@ different command line options to the test script. With the new tox-1.X we not only can do the same with 32 non-repetive configuration lines but we also produce 36 specific testenvs with specific dependencies and test commands:: - + [tox] envlist = {py24,py25,py26,py27}-{django11,django12,django13}-{nodb,pg,mysql}, docs @@ -281,8 +281,8 @@ commands:: nodb: pysqlite pg: psycopg2 mysql: MySQL-python - - commands = + + commands = nodb: {envpython} runtests.py {posargs} pg: {envpython} runtests.py {posargs} \ --DATABASE_ENGINE=postgresql_psycopg2 \ diff --git a/doc/config.txt b/doc/config.txt index 0dda013e..260a1ac5 100644 --- a/doc/config.txt +++ b/doc/config.txt @@ -99,7 +99,7 @@ Complete list of settings that you can put into ``testenv*`` sections: Must contain the substitution key ``{packages}`` which will be replaced by the packages to install. You should also accept ``{opts}`` if you are using - pip or easy_install -- it will contain index server options + pip -- it will contain index server options such as ``--pre`` (configured as ``pip_pre``) and potentially index-options from the deprecated :confval:`indexserver` option. @@ -189,6 +189,8 @@ Complete list of settings that you can put into ``testenv*`` sections: .. confval:: platform=REGEX + .. versionadded:: 2.0 + A testenv can define a new ``platform`` setting as a regular expression. If a non-empty expression is defined and does not match against the ``sys.platform`` string the test environment will be skipped. @@ -519,7 +521,7 @@ However, a better approach looks like this:: django15: Django>=1.5,<1.6 django16: Django>=1.6,<1.7 py26: unittest2 - commands = py.test + commands = pytest This uses two new facilities of tox-1.8: diff --git a/doc/example/basic.txt b/doc/example/basic.txt index 643ad604..3f0fa0f1 100644 --- a/doc/example/basic.txt +++ b/doc/example/basic.txt @@ -13,7 +13,7 @@ reside next to your ``setup.py`` file:: envlist = py26,py27 [testenv] deps=pytest # or 'nose' or ... - commands=py.test # or 'nosetests' or ... + commands=pytest # or 'nosetests' or ... To sdist-package, install and test your project, you can now type at the command prompt:: @@ -151,12 +151,7 @@ By default tox uses `pip`_ to install packages, both the package-under-test and any dependencies you specify in ``tox.ini``. You can fully customize tox's install-command through the testenv-specific :confval:`install_command=ARGV` setting. -For instance, to use ``easy_install`` instead of `pip`_:: - - [testenv] - install_command = easy_install {opts} {packages} - -Or to use pip's ``--find-links`` and ``--no-index`` options to specify +For instance, to use pip's ``--find-links`` and ``--no-index`` options to specify an alternative source for your dependencies:: [testenv] diff --git a/doc/example/general.txt b/doc/example/general.txt index 1a275494..eb14a44e 100644 --- a/doc/example/general.txt +++ b/doc/example/general.txt @@ -12,11 +12,11 @@ If you invoke ``tox`` like this:: the arguments after the ``--`` will be substituted everywhere where you specify ``{posargs}`` in your -test commands, for example using ``py.test``:: +test commands, for example using ``pytest``:: # in the testenv or testenv:NAME section of your tox.ini commands = - py.test {posargs} + pytest {posargs} or using ``nosetests``:: @@ -162,7 +162,7 @@ to deal with it in your commands section:: [testenv] commands = python setup.py develop - py.test + pytest Running ``setup.py develop`` is a common enough model that it has its own option:: diff --git a/doc/example/jenkins.txt b/doc/example/jenkins.txt index 32f185c1..260d14e8 100644 --- a/doc/example/jenkins.txt +++ b/doc/example/jenkins.txt @@ -32,11 +32,11 @@ using these steps: test results in the JUnit XML format. The last point requires that your test command creates JunitXML files, -for example with ``py.test`` it is done like this: +for example with ``pytest`` it is done like this: .. code-block:: ini - commands = py.test --junitxml=junit-{envname}.xml + commands = pytest --junitxml=junit-{envname}.xml @@ -80,7 +80,7 @@ If you are using a multi-configuration Jenkins job which collects JUnit Test results you will run into problems using the previous method of running the sphinx-build command because it will not generate JUnit results. To accomodate this issue one solution -is to have ``py.test`` wrap the sphinx-checks and create a +is to have ``pytest`` wrap the sphinx-checks and create a JUnit result file which wraps the result of calling sphinx-build. Here is an example: @@ -92,7 +92,7 @@ Here is an example: deps=sphinx py commands= - py.test --tb=line -v --junitxml=junit-{envname}.xml check_sphinx.py + pytest --tb=line -v --junitxml=junit-{envname}.xml check_sphinx.py 2. create a ``doc/check_sphinx.py`` file like this:: @@ -114,7 +114,7 @@ Here is an example: 3. run ``tox -e docs`` and then you may integrate this environment along with your other environments into Jenkins. -Note that ``py.test`` is only installed into the docs environment +Note that ``pytest`` is only installed into the docs environment and does not need to be in use or installed with any other environment. .. _`jenkins artifact example`: diff --git a/doc/example/platform.txt b/doc/example/platform.txt new file mode 100644 index 00000000..69785e5b --- /dev/null +++ b/doc/example/platform.txt @@ -0,0 +1,43 @@ + +Platform specification +============================ + +Basic multi-platform example +---------------------------- + +Assuming the following layout:: + + tox.ini # see below for content + setup.py # a classic distutils/setuptools setup.py file + +and the following ``tox.ini`` content: + +.. code-block:: ini + + [tox] + # platform specification support is available since version 2.0 + minversion=2.0 + envlist=py{27,36}-{mylinux,mymacos,mywindows} + + [testenv] + # environment will be skipped if regular expression does not match against the sys.platform string + platform= + mylinux: linux + mymacos: darwin + mywindows: win32 + + # you can specify dependencies and their versions based on platform filtered envirements + deps= + mylinux,mymacos: py==1.4.32 + mywindows: py==1.4.30 + + # upon tox invocation you will be greeted according to your platform + commands= + mylinux: python -c 'print("Hello, Linus!")' + mymacos: python -c 'print("Hello, Steve!")' + mywindows: python -c 'print("Hello, Bill!")' + +you can invoke ``tox`` in the directory where your ``tox.ini`` resides. +``tox`` creates two virtualenv environments with the ``python2.7`` and +``python3.6`` interpreters, respectively, and will then run the specified +command according to platform you invoke ``tox`` at. diff --git a/doc/example/pytest.txt b/doc/example/pytest.txt index 8876eb29..95bd8786 100644 --- a/doc/example/pytest.txt +++ b/doc/example/pytest.txt @@ -1,8 +1,8 @@ -py.test and tox +pytest and tox ================================= -It is easy to integrate `py.test`_ runs with tox. If you encounter +It is easy to integrate `pytest`_ runs with tox. If you encounter issues, please check if they are `listed as a known issue`_ and/or use the :doc:`support channels <../support>`. @@ -20,9 +20,9 @@ and the following ``tox.ini`` content:: envlist = py26,py31 [testenv] - deps=pytest # PYPI package providing py.test + deps=pytest # PYPI package providing pytest commands= - py.test \ + pytest \ {posargs} # substitute with tox' positional arguments you can now invoke ``tox`` in the directory where your ``tox.ini`` resides. @@ -47,12 +47,12 @@ and the following ``tox.ini`` content:: changedir=tests deps=pytest commands= - py.test \ - --basetemp={envtmpdir} \ # py.test tempdir setting + pytest \ + --basetemp={envtmpdir} \ # pytest tempdir setting {posargs} # substitute with tox' positional arguments you can invoke ``tox`` in the directory where your ``tox.ini`` resides. -Differently than in the previous example the ``py.test`` command +Differently than in the previous example the ``pytest`` command will be executed with a current working directory set to ``tests`` and the test run will use the per-virtualenv temporary directory. @@ -61,7 +61,7 @@ and the test run will use the per-virtualenv temporary directory. Using multiple CPUs for test runs ----------------------------------- -``py.test`` supports distributing tests to multiple processes and hosts +``pytest`` supports distributing tests to multiple processes and hosts through the `pytest-xdist`_ plugin. Here is an example configuration to make ``tox`` use this feature:: @@ -69,7 +69,7 @@ to make ``tox`` use this feature:: deps=pytest-xdist changedir=tests commands= - py.test \ + pytest \ --basetemp={envtmpdir} \ --confcutdir=.. \ -n 3 \ # use three sub processes @@ -81,12 +81,12 @@ Known Issues and limitations ----------------------------- **Too long filenames**. you may encounter "too long filenames" for temporarily -created files in your py.test run. Try to not use the "--basetemp" parameter. +created files in your pytest run. Try to not use the "--basetemp" parameter. -**installed-versus-checkout version**. ``py.test`` collects test +**installed-versus-checkout version**. ``pytest`` collects test modules on the filesystem and then tries to import them under their `fully qualified name`_. This means that if your test files are -importable from somewhere then your ``py.test`` invocation may end up +importable from somewhere then your ``pytest`` invocation may end up importing the package from the checkout directory rather than the installed package. diff --git a/doc/example/result.txt b/doc/example/result.txt index b3b95b48..21539982 100644 --- a/doc/example/result.txt +++ b/doc/example/result.txt @@ -14,31 +14,31 @@ This will create a json-formatted result file using this schema:: "testenvs": { "py27": { "python": { - "executable": "/home/hpk/p/tox/.tox/py27/bin/python", - "version": "2.7.3 (default, Aug 1 2012, 05:14:39) \n[GCC 4.6.3]", + "executable": "/home/hpk/p/tox/.tox/py27/bin/python", + "version": "2.7.3 (default, Aug 1 2012, 05:14:39) \n[GCC 4.6.3]", "version_info": [ 2, 7, 3, "final", 0 ] - }, + }, "test": [ { "output": "...", "command": [ - "/home/hpk/p/tox/.tox/py27/bin/py.test", - "--instafail", - "--junitxml=/home/hpk/p/tox/.tox/py27/log/junit-py27.xml", + "/home/hpk/p/tox/.tox/py27/bin/pytest", + "--instafail", + "--junitxml=/home/hpk/p/tox/.tox/py27/log/junit-py27.xml", "tests/test_config.py" - ], + ], "retcode": "0" } - ], + ], "setup": [] } - }, - "platform": "linux2", + }, + "platform": "linux2", "installpkg": { - "basename": "tox-1.6.0.dev1.zip", - "sha256": "b6982dde5789a167c4c35af0d34ef72176d0575955f5331ad04aee9f23af4326", + "basename": "tox-1.6.0.dev1.zip", + "sha256": "b6982dde5789a167c4c35af0d34ef72176d0575955f5331ad04aee9f23af4326", "md5": "27ead99fd7fa39ee7614cede6bf175a6" - }, - "toxversion": "1.6.0.dev1", + }, + "toxversion": "1.6.0.dev1", "reportversion": "1" } diff --git a/doc/examples.txt b/doc/examples.txt index a3e9d91f..c1114cad 100644 --- a/doc/examples.txt +++ b/doc/examples.txt @@ -12,4 +12,5 @@ tox configuration and usage examples example/general.txt example/jenkins.txt example/devenv.txt + example/platform.txt diff --git a/doc/index.txt b/doc/index.txt index ddd2b354..ae7924ae 100644 --- a/doc/index.txt +++ b/doc/index.txt @@ -25,7 +25,7 @@ Tox is a generic virtualenv_ management and test command line tool you can use f Basic example ----------------- -First, install ``tox`` with ``pip install tox`` or ``easy_install tox``. +First, install ``tox`` with ``pip install tox``. Then put basic information about your project and the test environments you want your project to run in into a ``tox.ini`` file residing right next to your ``setup.py`` file:: @@ -35,7 +35,7 @@ right next to your ``setup.py`` file:: envlist = py26,py27 [testenv] deps=pytest # install pytest in the venvs - commands=py.test # or 'nosetests' or ... + commands=pytest # or 'nosetests' or ... You can also try generating a ``tox.ini`` file automatically, by running ``tox-quickstart`` and then answering a few simple questions. @@ -61,7 +61,7 @@ Current features - installs your ``setup.py`` based project into each virtual environment - - test-tool agnostic: runs py.test, nose or unittests in a uniform manner + - test-tool agnostic: runs pytest, nose or unittests in a uniform manner * :doc:`(new in 2.0) plugin system <plugins>` to modify tox execution with simple hooks. diff --git a/doc/install.txt b/doc/install.txt index 6749def6..50cc7270 100644 --- a/doc/install.txt +++ b/doc/install.txt @@ -14,20 +14,19 @@ Install info in a nutshell **git repository**: https://github.com/tox-dev/tox -Installation with pip/easy_install +Installation with pip -------------------------------------- -Use one of the following commands:: +Use the following command:: pip install tox - easy_install tox It is fine to install ``tox`` itself into a virtualenv_ environment. Install from Checkout ------------------------- -Consult the Bitbucket page to get a checkout of the git repository: +Consult the GitHub page to get a checkout of the git repository: https://github.com/tox-dev/tox diff --git a/tests/test_config.py b/tests/test_config.py index 5ef05642..5e4889da 100644 --- a/tests/test_config.py +++ b/tests/test_config.py @@ -355,7 +355,7 @@ class TestIniParser: """) reader = SectionReader("mydefault", config._cfg, fallbacksections=['mydefault']) assert reader is not None - with py.test.raises(tox.exception.ConfigError): + with pytest.raises(tox.exception.ConfigError): reader.getstring("key2") def test_getstring_fallback_sections(self, tmpdir, newconfig): @@ -429,7 +429,7 @@ class TestIniParser: reader = SectionReader("section", config._cfg) x = reader.getstring("key1") assert x == "hello" - with py.test.raises(tox.exception.ConfigError): + with pytest.raises(tox.exception.ConfigError): reader.getstring("key2") def test_getstring_environment_substitution_with_default(self, monkeypatch, newconfig): @@ -476,7 +476,7 @@ class TestIniParser: """) reader = SectionReader("section", config._cfg) reader.addsubstitutions(item1="with space", item2="grr") - # py.test.raises(tox.exception.ConfigError, + # pytest.raises(tox.exception.ConfigError, # "reader.getargvlist('key1')") assert reader.getargvlist('key1') == [] x = reader.getargvlist("key2") @@ -486,12 +486,12 @@ class TestIniParser: def test_argvlist_windows_escaping(self, tmpdir, newconfig): config = newconfig(""" [section] - comm = py.test {posargs} + comm = pytest {posargs} """) reader = SectionReader("section", config._cfg) reader.addsubstitutions([r"hello\this"]) argv = reader.getargv("comm") - assert argv == ["py.test", "hello\\this"] + assert argv == ["pytest", "hello\\this"] def test_argvlist_multiline(self, tmpdir, newconfig): config = newconfig(""" @@ -502,7 +502,7 @@ class TestIniParser: """) reader = SectionReader("section", config._cfg) reader.addsubstitutions(item1="with space", item2="grr") - # py.test.raises(tox.exception.ConfigError, + # pytest.raises(tox.exception.ConfigError, # "reader.getargvlist('key1')") assert reader.getargvlist('key1') == [] x = reader.getargvlist("key2") @@ -550,7 +550,7 @@ class TestIniParser: reader = SectionReader("section", config._cfg) posargs = ['hello', 'world'] reader.addsubstitutions(posargs, item2="value2") - # py.test.raises(tox.exception.ConfigError, + # pytest.raises(tox.exception.ConfigError, # "reader.getargvlist('key1')") assert reader.getargvlist('key1') == [] argvlist = reader.getargvlist("key2") @@ -559,7 +559,7 @@ class TestIniParser: reader = SectionReader("section", config._cfg) reader.addsubstitutions([], item2="value2") - # py.test.raises(tox.exception.ConfigError, + # pytest.raises(tox.exception.ConfigError, # "reader.getargvlist('key1')") assert reader.getargvlist('key1') == [] argvlist = reader.getargvlist("key2") @@ -627,7 +627,7 @@ class TestIniParser: def test_substitution_with_multiple_words(self, newconfig): inisource = """ [section] - key = py.test -n5 --junitxml={envlogdir}/junit-{envname}.xml [] + key = pytest -n5 --junitxml={envlogdir}/junit-{envname}.xml [] """ config = newconfig(inisource) reader = SectionReader("section", config._cfg) @@ -635,7 +635,7 @@ class TestIniParser: reader.addsubstitutions(posargs, envlogdir='ENV_LOG_DIR', envname='ENV_NAME') expected = [ - 'py.test', '-n5', '--junitxml=ENV_LOG_DIR/junit-ENV_NAME.xml', 'hello', 'world' + 'pytest', '-n5', '--junitxml=ENV_LOG_DIR/junit-ENV_NAME.xml', 'hello', 'world' ] assert reader.getargvlist('key')[0] == expected @@ -672,8 +672,8 @@ class TestIniParser: assert reader.getbool("key1a") is True assert reader.getbool("key2") is False assert reader.getbool("key2a") is False - py.test.raises(KeyError, 'reader.getbool("key3")') - py.test.raises(tox.exception.ConfigError, 'reader.getbool("key5")') + pytest.raises(KeyError, 'reader.getbool("key3")') + pytest.raises(tox.exception.ConfigError, 'reader.getbool("key5")') class TestIniParserPrefix: @@ -864,6 +864,8 @@ class TestConfigTestEnv: assert "COMSPEC" in envconfig.passenv assert "TEMP" in envconfig.passenv assert "TMP" in envconfig.passenv + assert "NUMBER_OF_PROCESSORS" in envconfig.passenv + assert "USERPROFILE" in envconfig.passenv else: assert "TMPDIR" in envconfig.passenv assert "PATH" in envconfig.passenv @@ -986,7 +988,7 @@ class TestConfigTestEnv: 'some_install', '{packages}'] def test_install_command_must_contain_packages(self, newconfig): - py.test.raises(tox.exception.ConfigError, newconfig, """ + pytest.raises(tox.exception.ConfigError, newconfig, """ [testenv] install_command=pip install """) @@ -1032,7 +1034,7 @@ class TestConfigTestEnv: assert "py27" in config.envconfigs def test_substitution_error(tmpdir, newconfig): - py.test.raises(tox.exception.ConfigError, newconfig, """ + pytest.raises(tox.exception.ConfigError, newconfig, """ [testenv:py27] basepython={xyz} """) @@ -1308,7 +1310,7 @@ class TestConfigTestEnv: deps= {[testing:pytest]deps} """ - py.test.raises(ValueError, newconfig, [], inisource) + pytest.raises(ValueError, newconfig, [], inisource) def test_single_value_from_other_secton(self, newconfig, tmpdir): inisource = """ @@ -1511,7 +1513,7 @@ class TestGlobalOptions: [testenv:py27] basepython=python2.7 """ - # py.test.raises(tox.exception.ConfigError, + # pytest.raises(tox.exception.ConfigError, # "newconfig(['-exyz'], inisource)") config = newconfig([], inisource) assert config.envlist == ["py26"] @@ -1586,7 +1588,7 @@ class TestGlobalOptions: [tox] minversion = 10.0 """ - with py.test.raises(tox.exception.MinVersionError): + with pytest.raises(tox.exception.MinVersionError): newconfig([], inisource) def test_skip_missing_interpreters_true(self, tmpdir, newconfig, monkeypatch): @@ -2000,8 +2002,8 @@ class TestCmdInvocation: 'tox.ini': ''' [tox] envlist=py26,py27,py33,pypy,docs - description= py27: run py.test on Python 2.7 - py33: run py.test on Python 3.6 + description= py27: run pytest on Python 2.7 + py33: run pytest on Python 3.6 pypy: publish to pypy docs: document stuff notincluded: random extra @@ -2028,9 +2030,9 @@ class TestCmdInvocation: [tox] envlist=py26,py27,py33,pypy,docs [testenv] - description= py26: run py.test on Python 2.6 - py27: run py.test on Python 2.7 - py33: run py.test on Python 3.3 + description= py26: run pytest on Python 2.6 + py27: run pytest on Python 2.7 + py33: run pytest on Python 3.3 pypy: publish to pypy docs: document stuff notincluded: random extra @@ -2046,9 +2048,9 @@ class TestCmdInvocation: result = cmd.run("tox", "-lv") result.stdout.fnmatch_lines(""" default environments: - py26 -> run py.test on Python 2.6 - py27 -> run py.test on Python 2.7 - py33 -> run py.test on Python 3.3 + py26 -> run pytest on Python 2.6 + py27 -> run pytest on Python 2.7 + py33 -> run pytest on Python 3.3 pypy -> publish to pypy docs -> let me overwrite that """) @@ -2082,12 +2084,12 @@ class TestCmdInvocation: [tox] envlist={py27,py36}-{windows,linux} [testenv] - description= py27: run py.test on Python 2.7 - py36: run py.test on Python 3.6 + description= py27: run pytest on Python 2.7 + py36: run pytest on Python 3.6 windows: on Windows platform linux: on Linux platform docs: generate documentation - commands=py.test {posargs} + commands=pytest {posargs} [testenv:docs] changedir = docs @@ -2096,15 +2098,30 @@ class TestCmdInvocation: result = cmd.run("tox", "-av") result.stdout.fnmatch_lines(""" default environments: - py27-windows -> run py.test on Python 2.7 on Windows platform - py27-linux -> run py.test on Python 2.7 on Linux platform - py36-windows -> run py.test on Python 3.6 on Windows platform - py36-linux -> run py.test on Python 3.6 on Linux platform + py27-windows -> run pytest on Python 2.7 on Windows platform + py27-linux -> run pytest on Python 2.7 on Linux platform + py36-windows -> run pytest on Python 3.6 on Windows platform + py36-linux -> run pytest on Python 3.6 on Linux platform additional environments: docs -> generate documentation """) + def test_listenvs_all_verbose_description_no_additional_environments(self, cmd, initproj): + initproj('listenvs_all_verbose_description', filedefs={ + 'tox.ini': ''' + [tox] + envlist=py27,py36 + ''', + }) + result = cmd.run("tox", "-av") + result.stdout.fnmatch_lines(""" + default environments: + py27 -> [no description] + py36 -> [no description] + """) + assert 'additional environments' not in result.stdout.str() + def test_config_specific_ini(self, tmpdir, cmd): ini = tmpdir.ensure("hello.ini") result = cmd.run("tox", "-c", ini, "--showconfig") diff --git a/tests/test_quickstart.py b/tests/test_quickstart.py index 09fa733b..49b2b0c0 100644 --- a/tests/test_quickstart.py +++ b/tests/test_quickstart.py @@ -63,7 +63,7 @@ commands = py.test deps = pytest """.lstrip() - result = open('tox.ini').read() + result = read_tox() assert(result == expected_tox_ini) def test_quickstart_main_choose_individual_pythons_and_nose_adds_deps( @@ -105,7 +105,7 @@ commands = nosetests deps = nose """.lstrip() - result = open('tox.ini').read() + result = read_tox() assert(result == expected_tox_ini) def test_quickstart_main_choose_individual_pythons_and_trial_adds_deps( @@ -147,7 +147,7 @@ commands = trial deps = twisted """.lstrip() - result = open('tox.ini').read() + result = read_tox() assert(result == expected_tox_ini) def test_quickstart_main_choose_individual_pythons_and_pytest_adds_deps( @@ -188,7 +188,7 @@ commands = py.test deps = pytest """.lstrip() - result = open('tox.ini').read() + result = read_tox() assert(result == expected_tox_ini) def test_quickstart_main_choose_py27_and_pytest_adds_deps( @@ -221,7 +221,7 @@ commands = py.test deps = pytest """.lstrip() - result = open('tox.ini').read() + result = read_tox() assert(result == expected_tox_ini) def test_quickstart_main_choose_py27_and_py33_and_pytest_adds_deps( @@ -254,7 +254,7 @@ commands = py.test deps = pytest """.lstrip() - result = open('tox.ini').read() + result = read_tox() assert(result == expected_tox_ini) def test_quickstart_main_choose_all_pythons_and_pytest_adds_deps( @@ -287,7 +287,7 @@ commands = py.test deps = pytest """.lstrip() - result = open('tox.ini').read() + result = read_tox() assert(result == expected_tox_ini) def test_quickstart_main_choose_individual_pythons_and_defaults( @@ -329,7 +329,7 @@ commands = {envpython} setup.py test deps = """.lstrip() - result = open('tox.ini').read() + result = read_tox() assert(result == expected_tox_ini) def test_quickstart_main_existing_tox_ini(self, monkeypatch): @@ -376,7 +376,7 @@ commands = {envpython} setup.py test deps = """.lstrip() - result = open('tox-generated.ini').read() + result = read_tox('tox-generated.ini') assert(result == expected_tox_ini) @@ -408,7 +408,7 @@ deps = """.lstrip() d = tox._quickstart.process_input(d) tox._quickstart.generate(d) - result = open('tox.ini').read() + result = read_tox() # print(result) assert(result == expected_tox_ini) @@ -435,7 +435,7 @@ deps = """.lstrip() d = tox._quickstart.process_input(d) tox._quickstart.generate(d) - result = open('tox.ini').read() + result = read_tox() # print(result) assert(result == expected_tox_ini) @@ -461,7 +461,7 @@ deps = """.lstrip() d = tox._quickstart.process_input(d) tox._quickstart.generate(d) - result = open('tox.ini').read() + result = read_tox() # print(result) assert(result == expected_tox_ini) @@ -492,6 +492,11 @@ deps = """.lstrip() d = tox._quickstart.process_input(d) tox._quickstart.generate(d) - result = open('tox.ini').read() + result = read_tox() # print(result) assert(result == expected_tox_ini) + + +def read_tox(fname='tox.ini'): + with open(fname) as f: + return f.read() diff --git a/tests/test_venv.py b/tests/test_venv.py index 246581b6..3cd544f4 100644 --- a/tests/test_venv.py +++ b/tests/test_venv.py @@ -34,13 +34,11 @@ def test_getsupportedinterpreter(monkeypatch, newconfig, mocksession): assert py.path.local(interp).realpath() == py.path.local(sys.executable).realpath() monkeypatch.setattr(sys, 'platform', "win32") monkeypatch.setattr(venv.envconfig, 'basepython', 'jython') - py.test.raises(tox.exception.UnsupportedInterpreter, - venv.getsupportedinterpreter) + pytest.raises(tox.exception.UnsupportedInterpreter, venv.getsupportedinterpreter) monkeypatch.undo() monkeypatch.setattr(venv.envconfig, "envname", "py1") monkeypatch.setattr(venv.envconfig, 'basepython', 'notexistingpython') - py.test.raises(tox.exception.InterpreterNotFound, - venv.getsupportedinterpreter) + pytest.raises(tox.exception.InterpreterNotFound, venv.getsupportedinterpreter) monkeypatch.undo() # check that we properly report when no version_info is present info = NoInterpreterInfo(name=venv.name) @@ -345,7 +343,7 @@ def test_install_command_not_installed(newmocksession, monkeypatch): mocksession = newmocksession(['--recreate'], """ [testenv] commands= - py.test + pytest """) venv = mocksession.getenv('python') venv.test() @@ -356,10 +354,10 @@ def test_install_command_not_installed(newmocksession, monkeypatch): def test_install_command_whitelisted(newmocksession, monkeypatch): mocksession = newmocksession(['--recreate'], """ [testenv] - whitelist_externals = py.test + whitelist_externals = pytest xy* commands= - py.test + pytest xyz """) venv = mocksession.getenv('python') @@ -556,7 +554,7 @@ class TestVenvTest: monkeypatch.setenv("PIP_RESPECT_VIRTUALENV", "1") monkeypatch.setenv("PIP_REQUIRE_VIRTUALENV", "1") monkeypatch.setenv("__PYVENV_LAUNCHER__", "1") - py.test.raises(ZeroDivisionError, "venv.run_install_command(['qwe'], action=action)") + pytest.raises(ZeroDivisionError, "venv.run_install_command(['qwe'], action=action)") assert 'PIP_RESPECT_VIRTUALENV' not in os.environ assert 'PIP_REQUIRE_VIRTUALENV' not in os.environ assert '__PYVENV_LAUNCHER__' not in os.environ diff --git a/tests/test_z_cmdline.py b/tests/test_z_cmdline.py index b9783d53..93d2e366 100644 --- a/tests/test_z_cmdline.py +++ b/tests/test_z_cmdline.py @@ -42,11 +42,9 @@ def test_report_protocol(newconfig): def test__resolve_pkg(tmpdir, mocksession): distshare = tmpdir.join("distshare") spec = distshare.join("pkg123-*") - py.test.raises(tox.exception.MissingDirectory, - 'mocksession._resolve_pkg(spec)') + pytest.raises(tox.exception.MissingDirectory, 'mocksession._resolve_pkg(spec)') distshare.ensure(dir=1) - py.test.raises(tox.exception.MissingDependency, - 'mocksession._resolve_pkg(spec)') + pytest.raises(tox.exception.MissingDependency, 'mocksession._resolve_pkg(spec)') distshare.ensure("pkg123-1.3.5.zip") p = distshare.ensure("pkg123-1.4.5.zip") @@ -490,7 +488,7 @@ class TestToxRun: 'tox.ini': ''' [testenv] changedir=tests - commands= py.test --basetemp={envtmpdir} \ + commands= pytest --basetemp={envtmpdir} \ --junitxml=junit-{envname}.xml deps=pytest ''' @@ -590,7 +588,7 @@ def test_test_usedevelop(cmd, initproj, src_root): usedevelop=True changedir=tests commands= - py.test --basetemp={envtmpdir} --junitxml=junit-{envname}.xml [] + pytest --basetemp={envtmpdir} --junitxml=junit-{envname}.xml [] deps=pytest ''' }) @@ -5,9 +5,9 @@ envlist=py27,py26,py34,py33,py35,py36,pypy,flakes,py26-bare commands=echo {posargs} [testenv] -commands= py.test --timeout=180 {posargs:tests} +commands= pytest --timeout=180 {posargs:tests} -deps=pytest>=2.3.5 +deps=pytest>=3.0.0 pytest-timeout [testenv:py26-bare] @@ -27,15 +27,15 @@ changedir=doc deps=sphinx {[testenv]deps} commands= - py.test -v check_sphinx.py {posargs} + pytest -v check_sphinx.py {posargs} [testenv:flakes] deps = pytest-flakes>=0.2 pytest-pep8 commands = - py.test --flakes -m flakes tox tests - py.test --pep8 -m pep8 tox tests + pytest --flakes -m flakes tox tests + pytest --pep8 -m pep8 tox tests [testenv:dev] # required to make looponfail reload on every source code change @@ -43,7 +43,7 @@ usedevelop = True deps = pytest-xdist>=1.11 -commands = {posargs:py.test -s -x -f -v} +commands = {posargs:pytest -s -x -f -v} [pytest] rsyncdirs = tests tox diff --git a/tox/__init__.py b/tox/__init__.py index 4778ed81..73d095eb 100644 --- a/tox/__init__.py +++ b/tox/__init__.py @@ -1,9 +1,12 @@ -from pkg_resources import get_distribution +from pkg_resources import get_distribution, DistributionNotFound from .hookspecs import hookspec, hookimpl # noqa -_full_version = get_distribution('tox').version -__version__ = _full_version.split('+', 1)[0] +try: + _full_version = get_distribution(__name__).version + __version__ = _full_version.split('+', 1)[0] +except DistributionNotFound: + __version__ = '0.0.0.dev0' class exception: diff --git a/tox/_pytestplugin.py b/tox/_pytestplugin.py index 047df716..124fbb9d 100644 --- a/tox/_pytestplugin.py +++ b/tox/_pytestplugin.py @@ -142,7 +142,7 @@ def mocksession(request): class MockSession(Session): def __init__(self): self._clearmocks() - self.config = request.getfuncargvalue("newconfig")([], "") + self.config = request.getfixturevalue("newconfig")([], "") self.resultlog = ResultLog() self._actions = [] @@ -168,8 +168,8 @@ def mocksession(request): @pytest.fixture def newmocksession(request): - mocksession = request.getfuncargvalue("mocksession") - newconfig = request.getfuncargvalue("newconfig") + mocksession = request.getfixturevalue("mocksession") + newconfig = request.getfixturevalue("newconfig") def newmocksession(args, source, plugins=()): mocksession.config = newconfig(args, source, plugins=plugins) @@ -179,7 +179,7 @@ def newmocksession(request): class Cmd: def __init__(self, request): - self.tmpdir = request.getfuncargvalue("tmpdir") + self.tmpdir = request.getfixturevalue("tmpdir") self.request = request current = py.path.local() self.request.addfinalizer(current.chdir) @@ -189,7 +189,7 @@ class Cmd: def popen(self, argv, stdout, stderr, **kw): if not hasattr(py.std, 'subprocess'): - py.test.skip("no subprocess module") + pytest.skip("no subprocess module") env = os.environ.copy() env['PYTHONPATH'] = ":".join(filter(None, [ str(os.getcwd()), env.get('PYTHONPATH', '')])) diff --git a/tox/config.py b/tox/config.py index 2d240152..67501b9d 100755 --- a/tox/config.py +++ b/tox/config.py @@ -489,6 +489,10 @@ def tox_addoption(parser): passenv.add("COMSPEC") # needed for distutils cygwincompiler passenv.add("TEMP") passenv.add("TMP") + # for `multiprocessing.cpu_count()` on Windows + # (prior to Python 3.4). + passenv.add("NUMBER_OF_PROCESSORS") + passenv.add("USERPROFILE") # needed for `os.path.expanduser()`. else: passenv.add("TMPDIR") for spec in value: diff --git a/tox/session.py b/tox/session.py index 33ec2274..fd726ac5 100644 --- a/tox/session.py +++ b/tox/session.py @@ -109,7 +109,7 @@ class Action(object): logdir = self.session.config.logdir try: l = logdir.listdir("%s-*" % actionid) - except py.error.ENOENT: + except (py.error.ENOENT, py.error.ENOTDIR): logdir.ensure(dir=1) l = [] num = len(l) @@ -645,7 +645,7 @@ class Session: self.report.line(msg) for e in default: report_env(e) - if all_envs: + if all_envs and extra: if description: self.report.line('') self.report.line('additional environments:') |
