@@ -70,6 +70,18 @@ class UsageError(Exception):
7070 """ error in pytest usage or invocation"""
7171
7272
73+ def filename (path ):
74+ """Argparse type validator for filename arguments"""
75+ if os .path .isdir (path ):
76+ raise UsageError ("Must be a filename, given: {0}" .format (path ))
77+ return path
78+
79+ def directory (path ):
80+ """Argparse type validator for directory arguments"""
81+ if not os .path .isdir (path ):
82+ raise UsageError ("Must be a directory, given: {0}" .format (path ))
83+ return path
84+
7385_preinit = []
7486
7587default_plugins = (
@@ -996,7 +1008,6 @@ def _warn_about_missing_assertion(self, mode):
9961008 "(are you using python -O?)\n " )
9971009
9981010 def _preparse (self , args , addopts = True ):
999- import pytest
10001011 self ._initini (args )
10011012 if addopts :
10021013 args [:] = shlex .split (os .environ .get ('PYTEST_ADDOPTS' , '' )) + args
@@ -1009,9 +1020,7 @@ def _preparse(self, args, addopts=True):
10091020 self .pluginmanager .consider_env ()
10101021 self .known_args_namespace = ns = self ._parser .parse_known_args (args , namespace = self .option .copy ())
10111022 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 :
1023+ if self .known_args_namespace .confcutdir is None and self .inifile :
10151024 confcutdir = py .path .local (self .inifile ).dirname
10161025 self .known_args_namespace .confcutdir = confcutdir
10171026 try :
0 commit comments