Skip to content

unicode_literals break pytest_addoption hook #360

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
pytestbot opened this issue Oct 1, 2013 · 1 comment
Closed

unicode_literals break pytest_addoption hook #360

pytestbot opened this issue Oct 1, 2013 · 1 comment
Labels
type: bug problem that needs to be addressed

Comments

@pytestbot
Copy link
Contributor

Originally reported by: Floris Bruynooghe (BitBucket: flub, GitHub: flub)


When using unicode literals to add options in pytest_addoption argparse fails:

from __future__ import unicode_literals

def pytest_addoption(parser):
    parser.addoption('--foo', action='store', type='string', help='do foo')

Results in:

$ py.test
Traceback (most recent call last):
  File "/home/flub/.local/bin/py.test", line 9, in <module>
    load_entry_point('pytest==2.4.0', 'console_scripts', 'py.test')()
  File "/home/flub/.local/lib/python2.7/site-packages/_pytest/config.py", line 18, in main
    config = _prepareconfig(args, plugins)
  File "/home/flub/.local/lib/python2.7/site-packages/_pytest/config.py", line 63, in _prepareconfig
    pluginmanager=pluginmanager, args=args)
  File "/home/flub/.local/lib/python2.7/site-packages/_pytest/core.py", line 364, in __call__
    return self._docall(methods, kwargs)
  File "/home/flub/.local/lib/python2.7/site-packages/_pytest/core.py", line 375, in _docall
    res = mc.execute()
  File "/home/flub/.local/lib/python2.7/site-packages/_pytest/core.py", line 293, in execute
    res = method(**kwargs)
  File "/home/flub/.local/lib/python2.7/site-packages/_pytest/helpconfig.py", line 25, in pytest_cmdline_parse
    config = __multicall__.execute()
  File "/home/flub/.local/lib/python2.7/site-packages/_pytest/core.py", line 293, in execute
    res = method(**kwargs)
  File "/home/flub/.local/lib/python2.7/site-packages/_pytest/config.py", line 618, in pytest_cmdline_parse
    self.parse(args)
  File "/home/flub/.local/lib/python2.7/site-packages/_pytest/config.py", line 715, in parse
    args = self._parser.parse_setoption(args, self.option)
  File "/home/flub/.local/lib/python2.7/site-packages/_pytest/config.py", line 167, in parse_setoption
    parsedoption = self.parse(args)
  File "/home/flub/.local/lib/python2.7/site-packages/_pytest/config.py", line 145, in parse
    self.optparser = self._getparser()
  File "/home/flub/.local/lib/python2.7/site-packages/_pytest/config.py", line 160, in _getparser
    arggroup.add_argument(*n, **a)
  File "/usr/lib/python2.7/argparse.py", line 1286, in add_argument
    raise ValueError('%r is not callable' % (type_func,))
ValueError: u'string' is not callable

@pytestbot
Copy link
Contributor Author

Original comment by Floris Bruynooghe (BitBucket: flub, GitHub: flub):


Allow unicode strings in parser.add_argument()

This fixes issue360 by also converting unicode strings to the argparse
syntax instead of just native strings.

@pytestbot pytestbot added the type: bug problem that needs to be addressed label Jun 15, 2015
fkohlgrueber pushed a commit to fkohlgrueber/pytest that referenced this issue Oct 27, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug problem that needs to be addressed
Projects
None yet
Development

No branches or pull requests

1 participant