coverage-conditional-plugin icon indicating copy to clipboard operation
coverage-conditional-plugin copied to clipboard

Does this plugin works with module top-level pragmas.

Open proofit404 opened this issue 6 years ago • 2 comments

If I have a module in my library which should be imported only for Django 0.9.6, can I put # pragma: petrified_mammoth_shit right after coding comment?

Thanks for the awesome project :tada:

proofit404 avatar Mar 17 '20 07:03 proofit404

I'm just running into this same question. In our case we have config/darwin.py, config/linux.py and config/windows.py, each of which implements the interface of an ABC for a specific platform.

I need to be able to exclude all but the correct one from coverage reporting, depending on the platform being used.

I just tried this pyproject.toml:

[tool.coverage.run]
omit = [ "tests/*", "venv/*", "dist.win32/*" ]
plugins = [ "coverage_conditional_plugin" ]

[tool.coverage.coverage_conditional_plugin.rules]
sys-platform-win32 = "sys_platform == 'win32'"
sys-platform-not-win32 = "sys_platform != 'win32'"
sys-platform-darwin = "sys_platform == 'darwin'"
sys-platform-not-darwin = "sys_platform != 'darwin'"
sys-platform-linux = "sys_platform == 'linux'"
sys-platform-not-linux = "sys_platform != 'linux'"

And this in config/darwin.py, whilst running on Windows:

# pragma: sys-platform-not-darwin
...

But all that does is cause line 2 to be ignore, and everything from line 3 onwards to be reported as not covered.

Athanasius avatar Sep 30 '22 18:09 Athanasius

Sorry, but this does not work. We can add this into our configuration:

[tool.coverage.coverage_conditional_plugin.modules]
"module.name" = "sys_platform != 'linux'"

PRs are welcome!

sobolevn avatar Sep 30 '22 19:09 sobolevn