Allow unicode strings in parser.add_argument()

This fixes issue360 by also converting unicode strings to the argparse
syntax instead of just native strings.
This commit is contained in:
Floris Bruynooghe 2013-10-01 13:20:20 +01:00
parent 895d52471b
commit 1db6fc87c7
3 changed files with 14 additions and 2 deletions

View File

@ -1,7 +1,8 @@
Changes between 2.4.0 and X
-----------------------------------
- fix issue360: When using parser.addoption() unicode arguments to the
"type" keyword should also be converted to the respective types.
Changes between 2.3.5 and 2.4
-----------------------------------

View File

@ -238,7 +238,7 @@ class Argument:
pass
else:
# this might raise a keyerror as well, don't want to catch that
if isinstance(typ, str):
if isinstance(typ, py.builtin._basestring):
if typ == 'choice':
if self.TYPE_WARN:
py.std.warnings.warn(

View File

@ -113,6 +113,17 @@ class TestConfigAPI:
assert config.getoption(x) == "this"
pytest.raises(ValueError, "config.getoption('qweqwe')")
@pytest.mark.skipif('sys.version_info[:2] not in [(2, 6), (2, 7)]')
def test_config_getoption_unicode(self, testdir):
testdir.makeconftest("""
from __future__ import unicode_literals
def pytest_addoption(parser):
parser.addoption('--hello', type='string')
""")
config = testdir.parseconfig('--hello=this')
assert config.getoption('hello') == 'this'
def test_config_getvalueorskip(self, testdir):
config = testdir.parseconfig()
pytest.raises(pytest.skip.Exception,