Skip to content
Advertisement

Configute tox.ini to ignore library during tests with py27

I have the following tox.ini configuration file:

# Tox (http://tox.testrun.org/) is a tool for running tests
# in multiple virtualenvs. This configuration file will run the
# test suite on all supported python versions. To use it, "pip install tox"
# and then run "tox" from this directory.

[tox]
envlist = py27, py37, pycodestyle, pylint

[testenv]
commands =
    pytest --junitxml=unit-tests.xml --cov=xivo --cov-report term --cov-report xml:coverage.xml xivo
deps =
    -rrequirements.txt
    -rtest-requirements.txt
    pytest-cov

[testenv:pycodestyle]
# E501: line too long (80 chars)
commands =
    -sh -c 'pycodestyle --ignore=E501 xivo > pycodestyle.txt'
deps =
    pycodestyle
whitelist_externals =
    sh

[testenv:pylint]
commands =
    -sh -c 'pylint --rcfile=/usr/share/xivo-ci/pylintrc xivo > pylint.txt'
deps =
    -rrequirements.txt
    -rtest-requirements.txt
    pylint
whitelist_externals =
    sh

[testenv:black]
skip_install = true
deps = black
commands = black --skip-string-normalization .

[testenv:linters]
skip_install = true
deps =
    flake8
    flake8-colors
    black
commands =
    black --skip-string-normalization --check .
    flake8

[testenv:integration]
basepython = python3.7
usedevelop = true
deps = -rintegration_tests/test-requirements.txt
changedir = integration_tests
passenv =
    WAZO_TEST_DOCKER_OVERRIDE_EXTRA
commands =
    make test-setup
    pytest -v {posargs}
whitelist_externals =
    make
    sh

[flake8]
# E501: line too long (80 chars)
# W503: line break before binary operator
# E203: whitespace before ':' warnings
# NOTE(sileht):
# * xivo_config.py not python3 ready
exclude = .tox,.eggs,xivo/xivo_config.py
show-source = true
ignore = E501, E203, W503
max-line-length = 99
application-import-names = xivo

I have update my requirements.txt file in order to upgrade the version of Marshmallow from 3.0.0b14 to 3.10.0; like this:

https://github.com/wazo-platform/wazo-lib-rest-client/archive/master.zip
https://github.com/wazo-platform/wazo-auth-client/archive/master.zip
https://github.com/wazo-platform/xivo-bus/archive/master.zip
cheroot==6.5.4
flask==1.0.2
netifaces==0.10.4
psycopg2==2.7.7
pyyaml==3.13
python-consul==1.1.0
marshmallow==3.10.0
six==1.12.0
stevedore==1.29.0

Now my problem is that, when I run tox -e py37 everything works fine, but when I run this command tox -e py27, it fails. I get that the issue is that Marshmallow 3.10.0 is not supported on Python 2.7; so what I want to do is to change the tox.ini file in order to ignore Marshmallow library tests when it comes to running this command tox -e py27. I am new with tox, so I am not sure how to do this. Any help is welcome, thanks.

Advertisement

Answer

You need to mark those “Marshmellow” tests with a pytest marker.

https://docs.pytest.org/en/6.2.x/example/markers.html

e.g.

@pytest.mark.marshmellow
def test_xxx():
    ...

And then you need to run pytest -m "not marshmellow".

As you only want to do this for Python 2.7, you’d need to create a new testenv.

e.g.

[testenv:py27]
commands = pytest -m "not marshmellow" ...
User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement