I have the following code block in my module,
PARSER = argparse.ArgumentParser(description='This script gets ELB statistics '
'and look for any failed instances')
PARSER.add_argument('--profile', help='AWS profile - optional (only if multiple '
'accounts are setup in credentials file)', default='')
PARSER.add_argument('--region', help='AWS region. Defaults to ap-southeast-2',
default='ap-southeast-2')
PARSER.add_argument('--elb', help='DNS Name of the ELB to test', required=True)
PARSER.add_argument('--start', help='Start time of the load test (YYYY-MM-DD HH:MM:SS)',
required=True)
PARSER.add_argument('--end', help='End time of the load test (YYYY-MM-DD HH:MM:SS)',
required=True)
PARSER.add_argument('--debug', help='Print debugging information', action='store_true')
ARGS = PARSER.parse_args()
PROFILE = ARGS.profile
REGION = ARGS.region
ELB = ARGS.elb
START_TIME = format_date_string(ARGS.start)
END_TIME = format_date_string(ARGS.end)
DEBUG = ARGS.debug
if (START_TIME and END_TIME) is not None and START_TIME < END_TIME:
ASG_MON = ASGMonitor(elb_dns_name=ELB, profile_name=PROFILE, region_name=REGION, debug=DEBUG)
# used not keyword so the script exits with status 0 when function returns True (success)
exit(not ASG_MON.analyse_elb_for_failed_nodes(START_TIME, END_TIME))
else:
cprint('Error - Bad start and end date/time input')
exit(1)
I only want to include ASGMonitor class in my unit tests (in the same file). However argparse is causing issues with my tests,
py.test --cov elb_monitoring test --cov-fail-under 80 --cov-report term-missing
And I'm getting the error,
========================================================================================== test session starts ===========================================================================================
platform darwin -- Python 2.7.12, pytest-3.0.6, py-1.4.32, pluggy-0.4.0
rootdir: /Users/achinthag/Documents/Git_Workspace/ea-gatling/elb_monitoring, inifile:
plugins: cov-2.4.0
collected 0 items / 1 errors
---------- coverage: platform darwin, python 2.7.12-final-0 ----------
Name Stmts Miss Cover Missing
-----------------------------------------------------------------
src/elb_monitoring/__init__.py 0 0 100%
src/elb_monitoring/elb_monitor.py 87 65 25% 15-17, 22-26, 35-49, 53-55, 61-70, 74-90, 94-111, 129-142
-----------------------------------------------------------------
TOTAL 87 65 25%
================================================================================================= ERRORS =================================================================================================
_______________________________________________________________________________ ERROR collecting test/test_elb_monitor.py ________________________________________________________________________________
test/test_elb_monitor.py:3: in <module>
from elb_monitoring.elb_monitor import *
src/elb_monitoring/elb_monitor.py:127: in <module>
ARGS = PARSER.parse_args()
/usr/local/Cellar/python/2.7.12_2/Frameworks/Python.framework/Versions/2.7/lib/python2.7/argparse.py:1701: in parse_args
args, argv = self.parse_known_args(args, namespace)
/usr/local/Cellar/python/2.7.12_2/Frameworks/Python.framework/Versions/2.7/lib/python2.7/argparse.py:1733: in parse_known_args
namespace, args = self._parse_known_args(args, namespace)
/usr/local/Cellar/python/2.7.12_2/Frameworks/Python.framework/Versions/2.7/lib/python2.7/argparse.py:1957: in _parse_known_args
self.error(_('argument %s is required') % name)
/usr/local/Cellar/python/2.7.12_2/Frameworks/Python.framework/Versions/2.7/lib/python2.7/argparse.py:2374: in error
self.exit(2, _('%s: error: %s\n') % (self.prog, message))
/usr/local/Cellar/python/2.7.12_2/Frameworks/Python.framework/Versions/2.7/lib/python2.7/argparse.py:2362: in exit
_sys.exit(status)
E SystemExit: 2
-------------------------------------------------------------------------------------------- Captured stderr ---------------------------------------------------------------------------------------------
usage: py.test [-h] [--profile PROFILE] [--region REGION] --elb ELB --start
START --end END [--debug]
py.test: error: argument --elb is required
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Interrupted: 1 errors during collection !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
======================================================================================== 1 error in 0.61 seconds =========================================================================================
How can I ignore this bit of code from tests?
Thanks,