@@ -454,11 +454,11 @@ def addoption(self, *opts, **attrs):
454
454
"""
455
455
self ._anonymous .addoption (* opts , ** attrs )
456
456
457
- def parse (self , args ):
457
+ def parse (self , args , namespace = None ):
458
458
from _pytest ._argcomplete import try_argcomplete
459
459
self .optparser = self ._getparser ()
460
460
try_argcomplete (self .optparser )
461
- return self .optparser .parse_args ([str (x ) for x in args ])
461
+ return self .optparser .parse_args ([str (x ) for x in args ], namespace = namespace )
462
462
463
463
def _getparser (self ):
464
464
from _pytest ._argcomplete import filescompleter
@@ -476,25 +476,25 @@ def _getparser(self):
476
476
optparser .add_argument (FILE_OR_DIR , nargs = '*' ).completer = filescompleter
477
477
return optparser
478
478
479
- def parse_setoption (self , args , option ):
480
- parsedoption = self .parse (args )
479
+ def parse_setoption (self , args , option , namespace = None ):
480
+ parsedoption = self .parse (args , namespace = namespace )
481
481
for name , value in parsedoption .__dict__ .items ():
482
482
setattr (option , name , value )
483
483
return getattr (parsedoption , FILE_OR_DIR )
484
484
485
- def parse_known_args (self , args ):
485
+ def parse_known_args (self , args , namespace = None ):
486
486
"""parses and returns a namespace object with known arguments at this
487
487
point.
488
488
"""
489
- return self .parse_known_and_unknown_args (args )[0 ]
489
+ return self .parse_known_and_unknown_args (args , namespace = namespace )[0 ]
490
490
491
- def parse_known_and_unknown_args (self , args ):
491
+ def parse_known_and_unknown_args (self , args , namespace = None ):
492
492
"""parses and returns a namespace object with known arguments, and
493
493
the remaining arguments unknown at this point.
494
494
"""
495
495
optparser = self ._getparser ()
496
496
args = [str (x ) for x in args ]
497
- return optparser .parse_known_args (args )
497
+ return optparser .parse_known_args (args , namespace = namespace )
498
498
499
499
def addini (self , name , help , type = None , default = None ):
500
500
""" register an ini-file option.
@@ -778,10 +778,16 @@ def _ensure_removed_sysmodule(modname):
778
778
779
779
class CmdOptions (object ):
780
780
""" holds cmdline options as attributes."""
781
- def __init__ (self , ** kwargs ):
782
- self .__dict__ . update (kwargs )
781
+ def __init__ (self , values = () ):
782
+ self .update (values )
783
783
def __repr__ (self ):
784
784
return "<CmdOptions %r>" % (self .__dict__ ,)
785
+ def update (self , values ):
786
+ self .__dict__ .update (values )
787
+ def copy (self ):
788
+ copy = CmdOptions ()
789
+ copy .update (self .__dict__ )
790
+ return copy
785
791
786
792
class Notset :
787
793
def __repr__ (self ):
@@ -878,8 +884,8 @@ def cwd_relative_nodeid(self, nodeid):
878
884
def fromdictargs (cls , option_dict , args ):
879
885
""" constructor useable for subprocesses. """
880
886
config = get_config ()
887
+ config .option .update (option_dict )
881
888
config .parse (args , addopts = False )
882
- config .option .__dict__ .update (option_dict )
883
889
for x in config .option .plugins :
884
890
config .pluginmanager .consider_pluginarg (x )
885
891
return config
@@ -897,7 +903,7 @@ def pytest_load_initial_conftests(self, early_config):
897
903
self .pluginmanager ._set_initial_conftests (early_config .known_args_namespace )
898
904
899
905
def _initini (self , args ):
900
- ns , unknown_args = self ._parser .parse_known_and_unknown_args (args )
906
+ ns , unknown_args = self ._parser .parse_known_and_unknown_args (args , namespace = self . option . copy () )
901
907
r = determine_setup (ns .inifilename , ns .file_or_dir + unknown_args )
902
908
self .rootdir , self .inifile , self .inicfg = r
903
909
self ._parser .extra_info ['rootdir' ] = self .rootdir
@@ -918,7 +924,7 @@ def _preparse(self, args, addopts=True):
918
924
except ImportError as e :
919
925
self .warn ("I2" , "could not load setuptools entry import: %s" % (e ,))
920
926
self .pluginmanager .consider_env ()
921
- self .known_args_namespace = ns = self ._parser .parse_known_args (args )
927
+ self .known_args_namespace = ns = self ._parser .parse_known_args (args , namespace = self . option . copy () )
922
928
if self .known_args_namespace .confcutdir is None and self .inifile :
923
929
confcutdir = py .path .local (self .inifile ).dirname
924
930
self .known_args_namespace .confcutdir = confcutdir
@@ -956,7 +962,8 @@ def parse(self, args, addopts=True):
956
962
self ._preparse (args , addopts = addopts )
957
963
# XXX deprecated hook:
958
964
self .hook .pytest_cmdline_preparse (config = self , args = args )
959
- args = self ._parser .parse_setoption (args , self .option )
965
+ args = self ._parser .parse_setoption (args , self .option , namespace = self .option )
966
+ #args = self._parser.parse_known_args(args, namespace=self.option)
960
967
if not args :
961
968
cwd = os .getcwd ()
962
969
if cwd == self .rootdir :
0 commit comments