New issue 497: py.test fails when testing code that uses oslo.config and a
config file
https://bitbucket.org/hpk42/pytest/issue/497/pytest-fails-when-testing-code-that-uses
Philipp Sonntag:
Hello,
I was refactoring a tool in a package that I'm working on, to use oslo.config
for it's
configuration. After that, I wanted to re-run the tests I did so far, but
py.test fails with
```
#!python
(...)
> CONF(default_config_files=[_conffile])
/Library/Python/2.7/site-packages/oslo/config/cfg.py:1632: in __call__
> else sys.argv[1:])
/Library/Python/2.7/site-packages/oslo/config/cfg.py:2133: in _parse_cli_opts
> return self._parse_config_files()
/Library/Python/2.7/site-packages/oslo/config/cfg.py:2148: in
_parse_config_files
> return self._oparser.parse_args(self._args, namespace)
/Library/Python/2.7/site-packages/oslo/config/cfg.py:1496: in parse_args
> return super(_CachedArgumentParser, self).parse_args(args, namespace)
/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/argparse.py:1691:
in parse_args
> self.error(msg % ' '.join(argv))
/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/argparse.py:2361:
in error
> self.exit(2, _('%s: error: %s\n') % (self.prog, message))
/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/argparse.py:2349:
in exit
> _sys.exit(status)
E SystemExit: 2
-------------------------------------------------------------------------------------------------
Captured stderr
--------------------------------------------------------------------------------------------------
usage: py.test [-h] [--config-dir DIR] [--config-file PATH] [--version]
py.test: error: unrecognized arguments: -l tests/
=============================================================================================
1 error in 0.19 seconds
==============================================================================================
```
I cut of the first 3 lines of the traceback, cause of the package names etc,
sorry about that.
What happens in the package:
- the module (using oslo.config) get's imported.
- there's a method in it, *configure()*, that's run when imported
- it set's the configuration and runs * CONF(default_config_files=[_conffile])*
That seems to be where things start to fail. Without a config file being
defined, the tests
will run just fine.
I did run that with --trace-config, the output mentions 'active plugins' and
lists:
*pytestconfig : <_pytest.config.Config object at 0x108a906d0>*
Could a workaround be, to just 'disable' the plugin? I haven't checked for a
way to do so just
yet. I'm also not sure if I get 'plugin' right in this context and if this
could be disabled at all.
Nevertheless I'd like to keep using py.test for the tests and I'm (ok,
honestly: more or less)
using a TDD approach to this package. But with py.test failing . . .
Sorry, if anything you need to know is missing. Just let me know and I'll
update the issue.
I've attached three files, a sample module, a test file for it and a sample
config, that
reproduce the issue.
Regards,
Phil
BTW: I never used python unittest framework directly (through unittest.main()),
but this
fails for a complete different reason (import error for the package) and nose
fails for
the same reason as does py.test.
_______________________________________________
pytest-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pytest-commit