Merged in davehunt/pytest/env-addopts (pull request #241)
Support setting configuration using the PYTEST_ADDOPTS environment variable
This commit is contained in:
		
						commit
						459d6e610c
					
				
							
								
								
									
										1
									
								
								AUTHORS
								
								
								
								
							
							
						
						
									
										1
									
								
								AUTHORS
								
								
								
								
							|  | @ -46,3 +46,4 @@ Trevor Bekolay | ||||||
| David Mohr | David Mohr | ||||||
| Nicolas Delaby | Nicolas Delaby | ||||||
| Tom Viner | Tom Viner | ||||||
|  | Dave Hunt | ||||||
|  |  | ||||||
|  | @ -1,6 +1,8 @@ | ||||||
| 2.7.0.dev (compared to 2.6.4) | 2.7.0.dev (compared to 2.6.4) | ||||||
| ----------------------------- | ----------------------------- | ||||||
| 
 | 
 | ||||||
|  | - add ability to set command line options by environment variable PYTEST_ADDOPTS. | ||||||
|  | 
 | ||||||
| - fix issue655: work around different ways that cause python2/3 | - fix issue655: work around different ways that cause python2/3 | ||||||
|   to leak sys.exc_info into fixtures/tests causing failures in 3rd party code |   to leak sys.exc_info into fixtures/tests causing failures in 3rd party code | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -705,6 +705,7 @@ class Config(object): | ||||||
|     def _preparse(self, args, addopts=True): |     def _preparse(self, args, addopts=True): | ||||||
|         self._initini(args) |         self._initini(args) | ||||||
|         if addopts: |         if addopts: | ||||||
|  |             args[:] = shlex.split(os.environ.get('PYTEST_ADDOPTS', '')) + args | ||||||
|             args[:] = self.getini("addopts") + args |             args[:] = self.getini("addopts") + args | ||||||
|         self._checkversion() |         self._checkversion() | ||||||
|         self.pluginmanager.consider_preparse(args) |         self.pluginmanager.consider_preparse(args) | ||||||
|  |  | ||||||
|  | @ -60,6 +60,11 @@ progress output, you can write it into a configuration file:: | ||||||
|     [pytest] |     [pytest] | ||||||
|     addopts = -rsxX -q |     addopts = -rsxX -q | ||||||
| 
 | 
 | ||||||
|  | Alternatively, you can set a PYTEST_ADDOPTS environment variable to add command | ||||||
|  | line options while the environment is in use:: | ||||||
|  | 
 | ||||||
|  |     export PYTEST_ADDOPTS="-rsxX -q" | ||||||
|  | 
 | ||||||
| From now on, running ``pytest`` will add the specified options. | From now on, running ``pytest`` will add the specified options. | ||||||
| 
 | 
 | ||||||
| Builtin configuration file options | Builtin configuration file options | ||||||
|  |  | ||||||
|  | @ -18,12 +18,16 @@ class TestParseIni: | ||||||
|     def test_getcfg_empty_path(self, tmpdir): |     def test_getcfg_empty_path(self, tmpdir): | ||||||
|         getcfg([''], ['setup.cfg']) #happens on py.test "" |         getcfg([''], ['setup.cfg']) #happens on py.test "" | ||||||
| 
 | 
 | ||||||
|     def test_append_parse_args(self, testdir, tmpdir): |     def test_append_parse_args(self, testdir, tmpdir, monkeypatch): | ||||||
|  |         monkeypatch.setenv('PYTEST_ADDOPTS', '--color no -rs --tb="short"') | ||||||
|         tmpdir.join("setup.cfg").write(py.code.Source(""" |         tmpdir.join("setup.cfg").write(py.code.Source(""" | ||||||
|             [pytest] |             [pytest] | ||||||
|             addopts = --verbose |             addopts = --verbose | ||||||
|         """)) |         """)) | ||||||
|         config = testdir.parseconfig(tmpdir) |         config = testdir.parseconfig(tmpdir) | ||||||
|  |         assert config.option.color == 'no' | ||||||
|  |         assert config.option.reportchars == 's' | ||||||
|  |         assert config.option.tbstyle == 'short' | ||||||
|         assert config.option.verbose |         assert config.option.verbose | ||||||
|         #config = testdir.Config() |         #config = testdir.Config() | ||||||
|         #args = [tmpdir,] |         #args = [tmpdir,] | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue