From 7325a5fe2ee061c5ef48fabb1aa2c4abdf28b9a4 Mon Sep 17 00:00:00 2001 From: Dave Hunt Date: Fri, 23 Jan 2015 20:09:42 +0000 Subject: [PATCH] Support setting configuration using the PYTEST_ADDOPTS environment variable. --HG-- branch : env-addopts --- _pytest/config.py | 2 ++ testing/test_config.py | 7 +++++++ 2 files changed, 9 insertions(+) diff --git a/_pytest/config.py b/_pytest/config.py index c92374569..0d9beb3d3 100644 --- a/_pytest/config.py +++ b/_pytest/config.py @@ -705,6 +705,8 @@ class Config(object): def _preparse(self, args, addopts=True): self._initini(args) if addopts: + env_addopts = os.environ.get('PYTEST_ADDOPTS', '') + args[:] = env_addopts.replace('"', '').split() + args args[:] = self.getini("addopts") + args self._checkversion() self.pluginmanager.consider_preparse(args) diff --git a/testing/test_config.py b/testing/test_config.py index aa96c1d56..32e03f0d6 100644 --- a/testing/test_config.py +++ b/testing/test_config.py @@ -1,3 +1,5 @@ +import os + import py, pytest from _pytest.config import getcfg @@ -19,11 +21,16 @@ class TestParseIni: getcfg([''], ['setup.cfg']) #happens on py.test "" def test_append_parse_args(self, testdir, tmpdir): + os.environ['PYTEST_ADDOPTS'] = '--color no -rs --tb="short"' tmpdir.join("setup.cfg").write(py.code.Source(""" [pytest] addopts = --verbose """)) config = testdir.parseconfig(tmpdir) + del os.environ['PYTEST_ADDOPTS'] + assert config.option.color == 'no' + assert config.option.reportchars == 's' + assert config.option.tbstyle == 'short' assert config.option.verbose #config = testdir.Config() #args = [tmpdir,]