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:
parent
895d52471b
commit
1db6fc87c7
|
@ -1,7 +1,8 @@
|
||||||
Changes between 2.4.0 and X
|
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
|
Changes between 2.3.5 and 2.4
|
||||||
-----------------------------------
|
-----------------------------------
|
||||||
|
|
|
@ -238,7 +238,7 @@ class Argument:
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
# this might raise a keyerror as well, don't want to catch that
|
# 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 typ == 'choice':
|
||||||
if self.TYPE_WARN:
|
if self.TYPE_WARN:
|
||||||
py.std.warnings.warn(
|
py.std.warnings.warn(
|
||||||
|
|
|
@ -113,6 +113,17 @@ class TestConfigAPI:
|
||||||
assert config.getoption(x) == "this"
|
assert config.getoption(x) == "this"
|
||||||
pytest.raises(ValueError, "config.getoption('qweqwe')")
|
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):
|
def test_config_getvalueorskip(self, testdir):
|
||||||
config = testdir.parseconfig()
|
config = testdir.parseconfig()
|
||||||
pytest.raises(pytest.skip.Exception,
|
pytest.raises(pytest.skip.Exception,
|
||||||
|
|
Loading…
Reference in New Issue