From 1db6fc87c73e9ef51f7e4f47af5a0a953c5f8cdf Mon Sep 17 00:00:00 2001 From: Floris Bruynooghe Date: Tue, 1 Oct 2013 13:20:20 +0100 Subject: [PATCH] Allow unicode strings in parser.add_argument() This fixes issue360 by also converting unicode strings to the argparse syntax instead of just native strings. --- CHANGELOG | 3 ++- _pytest/config.py | 2 +- testing/test_config.py | 11 +++++++++++ 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index c631bcb5b..ea516deec 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -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 ----------------------------------- diff --git a/_pytest/config.py b/_pytest/config.py index 72276f853..36fb56425 100644 --- a/_pytest/config.py +++ b/_pytest/config.py @@ -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( diff --git a/testing/test_config.py b/testing/test_config.py index 9a8cab20a..cd4557dad 100644 --- a/testing/test_config.py +++ b/testing/test_config.py @@ -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,