Skip to content

Commit

Permalink
test: ensure lines are properly ignored during metacov
Browse files Browse the repository at this point in the history
  • Loading branch information
nedbat committed Aug 9, 2023
1 parent b02de96 commit e51b1f7
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 15 deletions.
1 change: 1 addition & 0 deletions metacov.ini
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ exclude_lines =
# cov.stop()
#
pragma: nested
cov.stop\(\)

# Abstract methods
raise NotImplementedError
Expand Down
30 changes: 15 additions & 15 deletions tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ def f1() -> None: # pragma: nested
def run_one_function(f: Callable[[], None]) -> None:
cov.erase()
cov.start()
f()
f() # pragma: nested
cov.stop()

fs = cov.get_data().measured_files()
Expand Down Expand Up @@ -367,7 +367,7 @@ def test_start_save_stop(self) -> None:
import_local_file("code1") # pragma: nested
cov.save() # pragma: nested
import_local_file("code2") # pragma: nested
cov.stop() # pragma: nested
cov.stop()
self.check_code1_code2(cov)

def test_start_save_nostop(self) -> None:
Expand All @@ -379,14 +379,14 @@ def test_start_save_nostop(self) -> None:
import_local_file("code2") # pragma: nested
self.check_code1_code2(cov) # pragma: nested
# Then stop it, or the test suite gets out of whack.
cov.stop() # pragma: nested
cov.stop()

def test_two_getdata_only_warn_once(self) -> None:
self.make_code1_code2()
cov = coverage.Coverage(source=["."], omit=["code1.py"])
cov.start()
import_local_file("code1") # pragma: nested
cov.stop() # pragma: nested
cov.stop()
# We didn't collect any data, so we should get a warning.
with self.assert_warnings(cov, ["No data was collected"]):
cov.get_data()
Expand All @@ -408,7 +408,7 @@ def test_two_getdata_warn_twice(self) -> None:
with self.assert_warnings(cov, ["No data was collected"]): # pragma: nested
cov.get_data() # pragma: nested
# Then stop it, or the test suite gets out of whack.
cov.stop() # pragma: nested
cov.stop()

def make_good_data_files(self) -> None:
"""Make some good data files."""
Expand Down Expand Up @@ -705,11 +705,11 @@ def test_dynamic_context_conflict(self) -> None:
cov = coverage.Coverage(source=["."])
cov.set_option("run:dynamic_context", "test_function")
cov.start()
with pytest.warns(Warning) as warns:
with pytest.warns(Warning) as warns: # pragma: nested
# Switch twice, but only get one warning.
cov.switch_context("test1") # pragma: nested
cov.switch_context("test2") # pragma: nested
cov.stop() # pragma: nested
cov.switch_context("test1")
cov.switch_context("test2")
cov.stop()
assert_coverage_warnings(warns, "Conflicting dynamic contexts (dynamic-conflict)")

def test_unknown_dynamic_context(self) -> None:
Expand All @@ -728,7 +728,7 @@ def test_switch_context_unstarted(self) -> None:
cov.start()
cov.switch_context("test2") # pragma: nested

cov.stop() # pragma: nested
cov.stop()
with pytest.raises(CoverageException, match=msg):
cov.switch_context("test3")

Expand All @@ -752,7 +752,7 @@ def test_run_debug_sys(self) -> None:
cov = coverage.Coverage()
cov.start()
d = dict(cov.sys_info()) # pragma: nested
cov.stop() # pragma: nested
cov.stop()
assert cast(str, d['data_file']).endswith(".coverage")


Expand Down Expand Up @@ -902,7 +902,7 @@ def coverage_usepkgs_counts(self, **kwargs: TCovKwargs) -> Dict[str, int]:
cov = coverage.Coverage(**kwargs)
cov.start()
import usepkgs # pragma: nested # pylint: disable=import-error, unused-import
cov.stop() # pragma: nested
cov.stop()
with self.assert_warnings(cov, []):
data = cov.get_data()
summary = line_counts(data)
Expand All @@ -919,7 +919,7 @@ def test_source_include_exclusive(self) -> None:
cov = coverage.Coverage(source=["pkg1"], include=["pkg2"])
with self.assert_warnings(cov, ["--include is ignored because --source is set"]):
cov.start()
cov.stop() # pragma: nested
cov.stop()

def test_source_package_as_package(self) -> None:
assert not os.path.isdir("pkg1")
Expand Down Expand Up @@ -995,7 +995,7 @@ def coverage_usepkgs(self, **kwargs: TCovKwargs) -> Iterable[str]:
cov = coverage.Coverage()
cov.start()
import usepkgs # pragma: nested # pylint: disable=import-error, unused-import
cov.stop() # pragma: nested
cov.stop()
report = io.StringIO()
cov.report(file=report, **kwargs)
return report.getvalue()
Expand All @@ -1014,7 +1014,7 @@ def coverage_usepkgs(self, **kwargs: TCovKwargs) -> Iterable[str]:
cov = coverage.Coverage()
cov.start()
import usepkgs # pragma: nested # pylint: disable=import-error, unused-import
cov.stop() # pragma: nested
cov.stop()
cov.xml_report(outfile="-", **kwargs)
return self.stdout()

Expand Down

0 comments on commit e51b1f7

Please sign in to comment.