Skip to content

Commit

Permalink
Merge remote-tracking branch 'nedbat/nedbat/finish-1700' into suppres…
Browse files Browse the repository at this point in the history
…s-path0
  • Loading branch information
flying-sheep committed Nov 19, 2023
2 parents 1cdb88f + 66d3d34 commit f0eb6b4
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
5 changes: 5 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,17 @@ development at the same time, such as 4.5.x and 5.0.
Unreleased
----------

- Fix: the PYTHONSAFEPATH environment variable new in Python 3.11 is properly
supported, closing `issue 1696`_. Thanks, `Philipp A. <pull 1700_>`_.

- Added new :ref:`debug options <cmd_run_debug>`:

- ``pytest`` writes the pytest test name into the debug output.

- ``dataop2`` writes the full data being added to CoverageData objects.

.. _issue 1696: https://github.com/nedbat/coveragepy/issues/1696
.. _pull 1700: https://github.com/nedbat/coveragepy/pull/1700

.. scriv-start-here
Expand Down
19 changes: 19 additions & 0 deletions tests/test_process.py
Original file line number Diff line number Diff line change
Expand Up @@ -786,6 +786,25 @@ def test_coverage_zip_is_like_python(self) -> None:
actual = self.run_command(f"python {cov_main} run run_me.py")
self.assert_tryexecfile_output(expected, actual)

def test_pythonsafepath(self) -> None:
with open(TRY_EXECFILE) as f:
self.make_file("run_me.py", f.read())
self.set_environ("PYTHONSAFEPATH", "1")
expected = self.run_command("python run_me.py")
actual = self.run_command("coverage run run_me.py")
self.assert_tryexecfile_output(expected, actual)

@pytest.mark.skipif(env.PYVERSION < (3, 11), reason="PYTHONSAFEPATH is new in 3.11")
def test_pythonsafepath_dashm(self) -> None:
with open(TRY_EXECFILE) as f:
self.make_file("with_main/__main__.py", f.read())

self.set_environ("PYTHONSAFEPATH", "1")
expected = self.run_command("python -m with_main")
actual = self.run_command("coverage run -m with_main")
assert re.search(f"No module named '?with_main'?", actual)
assert re.search(f"No module named '?with_main'?", expected)

def test_coverage_custom_script(self) -> None:
# https://github.com/nedbat/coveragepy/issues/678
# If sys.path[0] isn't the Python default, then coverage.py won't
Expand Down

0 comments on commit f0eb6b4

Please sign in to comment.