Skip to content

Commit

Permalink
Exclude test coverage in defensive lines
Browse files Browse the repository at this point in the history
  • Loading branch information
JakobGM committed Feb 14, 2018
1 parent 7430765 commit a63f7df
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 8 deletions.
28 changes: 28 additions & 0 deletions .coveragerc
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# .coveragerc to control coverage.py
[run]
branch = True

omit =
setup.py

[report]
exclude_lines =
# Have to re-enable the standard pragma
pragma: no cover

# Don't complain about missing debug-only code:
def __repr__
if self\.debug

# Don't complain if tests don't hit defensive assertion code:
raise AssertionError
raise NotImplementedError

# Don't complain if non-runnable code isn't run:
if 0:
if __name__ == .__main__.:

ignore_errors = True


# vim:filetype=dosini
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ install:
- pip install -r requirements.txt
- pip install coveralls
script:
- coverage run --source='.' -m py.test -vv --runslow
- coverage run --rcfile=.coveragerc --source='.' -m py.test -vv --runslow
- coverage report -m
after_success:
- coveralls
Expand Down
2 changes: 1 addition & 1 deletion astrality/astrality.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ def exit_handler(signal=None, frame=None) -> None:
module_manager.time_until_next_period().total_seconds()
)

except KeyboardInterrupt:
except KeyboardInterrupt: # pragma: no cover
exit_handler()

def other_astrality_pids() -> Set[int]:
Expand Down
4 changes: 2 additions & 2 deletions astrality/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
try:
from yaml import CLoader as Loader, CDumper as Dumper # type: ignore
logger.info('Using LibYAML bindings for faster .yaml parsing.')
except ImportError:
except ImportError: # pragma: no cover
from yaml import Loader, Dumper
logger.warning(
'LibYAML not installed.'
Expand Down Expand Up @@ -96,7 +96,7 @@ def dict_from_config_file(
containing all the environment variables.
"""

if not config_file.is_file():
if not config_file.is_file(): # pragma: no cover
error_msg = f'Could not load config file "{config_file}".'
logger.critical(error_msg)
raise RuntimeError(error_msg)
Expand Down
9 changes: 5 additions & 4 deletions conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ def pytest_collection_modifyitems(config, items):
if config.getoption("--runslow"):
# --runslow given in cli: do not skip slow tests
return
skip_slow = pytest.mark.skip(reason="need --runslow option to run")
for item in items:
if "slow" in item.keywords:
item.add_marker(skip_slow)
else: # pragma: no cover
skip_slow = pytest.mark.skip(reason="need --runslow option to run")
for item in items:
if "slow" in item.keywords:
item.add_marker(skip_slow)

0 comments on commit a63f7df

Please sign in to comment.