Pytest: cannot use "not" markers with tox.ini's posargs

Issue #340 on hold
Jack Nicholson
created an issue

I have a custom marker in pytest registered as dev in my tox.ini

tox.ini excerpt:

[testenv]
commands =
    find . -name '*.pyc' -delete
    py.test -v -rsx --color=yes {posargs:tests/}
    rm -rf *.egg-info
[pytest]
markers =
    dev: tests for just the development environment

You can see pytest can see the marker

$ py.test --markers
@pytest.mark.dev: tests for just the development environment

I can use my marker using py.test -m dev tests/ and like this tox -- -m dev tests/ but cannot use it like this tox -- -m "not dev" tests/

pytest==2.9.0
tox==2.3.1

on Windows 8.1 with Python 2.7.11

Output:

$ tox -e all -- -m "not dev"
all installed: alabaster==0.7.8,Babel==2.3.4,colorama==0.3.7,docutils==0.12,Jinja2==2.8,MarkupSafe==0.23,py==1.4.31,Pygments==2.1.3,PyMySQL==0.7.2,pytest==2.9.2,pytz==2016.4,PyYAML==3.11,requests==2.9.1,requests-oauth==0.4.1,six==1.10.0,snowballstemmer==1.2.1,Sphinx==1.3.5,sphinx-rtd-theme==0.1.9
all runtests: PYTHONHASHSEED='846'
all runtests: commands[0] | rm -rf *.egg-info
all runtests: commands[1] | find . -name *.pyc -delete
all runtests: commands[2] | rm -f cookie-tmp.txt
all runtests: commands[3] | py.test -v -rsx --color=yes -m not dev
============================= test session starts =============================
platform win32 -- Python 2.7.11, pytest-2.9.2, py-1.4.31, pluggy-0.3.1 -- c:\users\user\git\automation-wb-api\requests\.tox\all\scripts\python.exe
cachedir: .cache
rootdir: C:\Users\user\git\automation-wb-api\requests, inifile: tox.ini

======================== no tests ran in 0.04 seconds =========================
ERROR: file not found: dev
ERROR: InvocationError: 'C:\\Users\\user\\git\\automation-wb-api\\requests\\.tox\\all\\Scripts\\py.test.EXE -v -rsx --color=yes -m not dev'
___________________________________ summary ___________________________________
ERROR:   all: commands failed

Comments (7)

  1. Jack Nicholson reporter

    A workaround is to create environments that use markers or expressions in the commands.

    [testenv]
    commands = 
        dev: py.test -v -rsx --color=yes -m "dev" {posargs:tests/}
    
  2. Jack Nicholson reporter

    It looks like by checking for the -m field after args = config.option.args in posargsOption.postprocess() and inserting quotes around the field will allow pytest to get the options correctly.

            try:
                markerindex = args.index('-m') + 1
                args[markerindex] = "'{0}'".format(args[markerindex])
            except:
               pass
    

    Is this the best location and best method to solve this issue?

    Thanks, J

  3. Log in to comment