I am using pytest, with coveragerc to measure code coverage of my source file, which is given below
import argparse
import sys
if __name__ == '__main__':
parser = argparse.ArgumentParser()
parser.add_argument('--input_dir', type=str, required=True, help='fully qualified directory path')
arguments = parser.parse_known_args(sys.argv[1:])
my_func(arguments.input_dir)
My coveragerc configuration is given below
[report]
exclude_lines =
if __name__ == .__main__.:
pytest config
[pytest]
python_files=*_test.py
addopts = --cov='.' --cov-config=.coveragerc
Tests to validate functionality in my_func
exist, but not for the lines of code under main function. I would like to be able to exclude all lines within the main function from the code coverage because its functionality just initialises the parser and calls the another function.