@@ -70,6 +70,28 @@ class UsageError(Exception):
7070 """ error in pytest usage or invocation"""
7171
7272
73+ def filename_arg (path , optname ):
74+ """ Argparse type validator for filename arguments.
75+
76+ :path: path of filename
77+ :optname: name of the option
78+ """
79+ if os .path .isdir (path ):
80+ raise UsageError ("{0} must be a filename, given: {1}" .format (optname , path ))
81+ return path
82+
83+
84+ def directory_arg (path , optname ):
85+ """Argparse type validator for directory arguments.
86+
87+ :path: path of directory
88+ :optname: name of the option
89+ """
90+ if not os .path .isdir (path ):
91+ raise UsageError ("{0} must be a directory, given: {1}" .format (optname , path ))
92+ return path
93+
94+
7395_preinit = []
7496
7597default_plugins = (
@@ -996,7 +1018,6 @@ def _warn_about_missing_assertion(self, mode):
9961018 "(are you using python -O?)\n " )
9971019
9981020 def _preparse (self , args , addopts = True ):
999- import pytest
10001021 self ._initini (args )
10011022 if addopts :
10021023 args [:] = shlex .split (os .environ .get ('PYTEST_ADDOPTS' , '' )) + args
@@ -1009,9 +1030,7 @@ def _preparse(self, args, addopts=True):
10091030 self .pluginmanager .consider_env ()
10101031 self .known_args_namespace = ns = self ._parser .parse_known_args (args , namespace = self .option .copy ())
10111032 confcutdir = self .known_args_namespace .confcutdir
1012- if confcutdir and not os .path .isdir (confcutdir ):
1013- raise pytest .UsageError ('--confcutdir must be a directory, given: {0}' .format (confcutdir ))
1014- if confcutdir is None and self .inifile :
1033+ if self .known_args_namespace .confcutdir is None and self .inifile :
10151034 confcutdir = py .path .local (self .inifile ).dirname
10161035 self .known_args_namespace .confcutdir = confcutdir
10171036 try :
0 commit comments