Skip to content

Commit cbb2c55

Browse files
authored
Merge pull request #3304 from RonnyPfannschmidt/cmdoptions-removal
remove CmdOptions since we can use argparse.Namespace()
2 parents 4175ed8 + 87f2003 commit cbb2c55

File tree

2 files changed

+7
-18
lines changed

2 files changed

+7
-18
lines changed

_pytest/config.py

+6-18
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import traceback
66
import types
77
import warnings
8-
8+
import copy
99
import six
1010
import py
1111
# DON't import pytest here because it causes import cycle troubles
@@ -68,7 +68,7 @@ def main(args=None, plugins=None):
6868
return 4
6969

7070

71-
class cmdline(object): # compatibility namespace
71+
class cmdline(object): # NOQA compatibility namespace
7272
main = staticmethod(main)
7373

7474

@@ -845,19 +845,6 @@ def _ensure_removed_sysmodule(modname):
845845
pass
846846

847847

848-
class CmdOptions(object):
849-
""" holds cmdline options as attributes."""
850-
851-
def __init__(self, values=()):
852-
self.__dict__.update(values)
853-
854-
def __repr__(self):
855-
return "<CmdOptions %r>" % (self.__dict__,)
856-
857-
def copy(self):
858-
return CmdOptions(self.__dict__)
859-
860-
861848
class Notset(object):
862849
def __repr__(self):
863850
return "<NOTSET>"
@@ -885,7 +872,7 @@ class Config(object):
885872
def __init__(self, pluginmanager):
886873
#: access to command line option as attributes.
887874
#: (deprecated), use :py:func:`getoption() <_pytest.config.Config.getoption>` instead
888-
self.option = CmdOptions()
875+
self.option = argparse.Namespace()
889876
_a = FILE_OR_DIR
890877
self._parser = Parser(
891878
usage="%%(prog)s [options] [%s] [%s] [...]" % (_a, _a),
@@ -989,7 +976,7 @@ def pytest_load_initial_conftests(self, early_config):
989976
self.pluginmanager._set_initial_conftests(early_config.known_args_namespace)
990977

991978
def _initini(self, args):
992-
ns, unknown_args = self._parser.parse_known_and_unknown_args(args, namespace=self.option.copy())
979+
ns, unknown_args = self._parser.parse_known_and_unknown_args(args, namespace=copy.copy(self.option))
993980
r = determine_setup(ns.inifilename, ns.file_or_dir + unknown_args, warnfunc=self.warn,
994981
rootdir_cmd_arg=ns.rootdir or None)
995982
self.rootdir, self.inifile, self.inicfg = r
@@ -1054,7 +1041,8 @@ def _preparse(self, args, addopts=True):
10541041
self.pluginmanager.consider_preparse(args)
10551042
self.pluginmanager.load_setuptools_entrypoints('pytest11')
10561043
self.pluginmanager.consider_env()
1057-
self.known_args_namespace = ns = self._parser.parse_known_args(args, namespace=self.option.copy())
1044+
self.known_args_namespace = ns = self._parser.parse_known_args(
1045+
args, namespace=copy.copy(self.option))
10581046
if self.known_args_namespace.confcutdir is None and self.inifile:
10591047
confcutdir = py.path.local(self.inifile).dirname
10601048
self.known_args_namespace.confcutdir = confcutdir

changelog/3304.trivial

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Internal refactoring to better integrate with argparse.

0 commit comments

Comments
 (0)