os.system working with lcov --remove but subprocess.call is not

112 views Asked by At

I'm using lcov, I want to exclude some files/directories from my coverage reports.

When I use os.system():

os.system("lcov --remove  build/unit_test_coverage.info \'*test*\' \'*mock*\' -o build/unit_test_coverage.info")

It excludes the files/directories as I expect.

But when I use subprocess.call() like this:

subprocess.call(["lcov", "--remove", "build/unit_test_coverage.info", "\'*test*\'", "\'*mock*\'", "-o", "build/unit_test_coverage.info"])

The files/directories are not exluded.

Anyone know why?

1

There are 1 answers

0
Lucas On BEST ANSWER

subprocess.call does not use a shell by default so you do not need to escape or protect "*". Do it like this:

subprocess.call(["lcov", "--remove", "build/unit_test_coverage.info", "*test*", "*mock*", "-o", "build/unit_test_coverage.info"])

The docs for subprocess.call say to look at the docs for Popen to see how the arguments work. There it says that the shell is only used if you also specify shell=True and give it a string as first argument. There is also a "note" block there explaining this stuff.