Skip to content

Commit

Permalink
Merge pull request #37 from ymyzk/allow-env-override
Browse files Browse the repository at this point in the history
Allow overriding envlist
  • Loading branch information
ymyzk authored Oct 4, 2020
2 parents ed8cebe + 62a218b commit 0f9f5f4
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 0 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -215,3 +215,8 @@ deps =

See [tox's documentation about factor-conditional settings](https://tox.readthedocs.io/en/latest/config.html#factors-and-factor-conditional-settings) as well.

### Overriding Environments to Run
_Changed in 2.0_: When a list of environments to run is specified explicitly via `-e` option or `TOXENV` environment variable ([tox's help](https://tox.readthedocs.io/en/latest/example/general.html#selecting-one-or-more-environments-to-run-tests-against)),
tox-gh-actions respects the given environments and simply runs the given environments without enforcing its configuration.

Before 2.0, tox-gh-actions was always enforcing its configuration even when a list of environments is given explicitly.
17 changes: 17 additions & 0 deletions src/tox_gh_actions/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ def tox_configure(config):
verbosity1("tox is not running in GitHub Actions")
verbosity1("tox-gh-actions won't override envlist")
return
elif is_env_specified(config):
verbosity1("envlist is explicitly given via TOXENV or -e option")
verbosity1("tox-gh-actions won't override envlist")
return

config.envlist_default = config.envlist = envlist


Expand Down Expand Up @@ -113,6 +118,18 @@ def is_running_on_actions():
return os.environ.get("GITHUB_ACTIONS") == "true"


def is_env_specified(config):
# type: (Config) -> None
"""Returns True when environments are explicitly given"""
if os.environ.get("TOXENV"):
# When TOXENV is a non-empty string
return True
elif config.option.env is not None:
# When command line argument (-e) is given
return True
return False


# The following function was copied from
# https://github.com/tox-dev/tox-travis/blob/0.12/src/tox_travis/utils.py#L11-L32
# which is licensed under MIT LICENSE
Expand Down
16 changes: 16 additions & 0 deletions tests/test_plugin.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import pytest
from tox.config import Config

from tox_gh_actions import plugin

Expand Down Expand Up @@ -292,3 +293,18 @@ def test_get_version(mocker, version, info, expected):
def test_is_running_on_actions(mocker, environ, expected):
mocker.patch("tox_gh_actions.plugin.os.environ", environ)
assert plugin.is_running_on_actions() == expected


@pytest.mark.parametrize("option_env,environ,expected", [
(None, {"TOXENV": "flake8"}, True),
(["py27,py38"], {}, True),
(["py27", "py38"], {}, True),
(["py27"], {"TOXENV": "flake8"}, True),
(None, {}, False),
])
def test_is_env_specified(mocker, option_env, environ, expected):
mocker.patch("tox_gh_actions.plugin.os.environ", environ)
option = mocker.MagicMock()
option.env = option_env
config = Config(None, option, None, mocker.MagicMock(), [])
assert plugin.is_env_specified(config) == expected

0 comments on commit 0f9f5f4

Please sign in to comment.