-
-
Notifications
You must be signed in to change notification settings - Fork 436
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: runpy.run_path(path) crashes with pathlib.Path #1819
Conversation
Thanks, I see there is a problem. I'd want to understand the full call stack to know where I should be accepting |
Thanks @nedbat! It crossed my mind that it could originate with pytest or pytest-cov, since there's something finicky going on between runpy and the
This yields the considerably shorter stacktrace
After some messing around I found that usually the function receives a str, but it receives a I pushed a change inserting a conversion there instead of in the previous place. So that fix will equally well solve the problem without the need to think about But I don't know if there's any documentation that could reveal what types |
No worries, when a bug report mentions pytest-cov, the first thing I do is try to reproduce it without it. I also saw it with just I like the latest change: it feels like the right place. Do you want to add yourself to CONTRIBUTORS and add a changelog entry? I can take care of it if you like. |
I have added a test in what I perceive to be a reasonably correct place.
Thanks. Since the list of unreleased changes is empty, I was not sure whether to add a note before or after |
I just pushed a lint-fixing change but you have apparently already done something about it. Feel free to ignore/adapt/close this. I am not sure whether this should actually be considered an issue with runpy. The docs (https://docs.python.org/3/reference/import.html#file__) say rather clearly that Thanks a lot! |
I also beefed up the test a bit in askhl#1. You can merge that pull request to get my changes. |
Nice. It's merged. |
Thanks! |
This is now released as part of coverage 7.6.1. |
[![Mend Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com) This PR contains the following updates: | Package | Change | Age | Adoption | Passing | Confidence | |---|---|---|---|---|---| | [coverage](https://togithub.com/nedbat/coveragepy) | `==7.6.0` -> `==7.6.1` | [![age](https://developer.mend.io/api/mc/badges/age/pypi/coverage/7.6.1?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![adoption](https://developer.mend.io/api/mc/badges/adoption/pypi/coverage/7.6.1?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![passing](https://developer.mend.io/api/mc/badges/compatibility/pypi/coverage/7.6.0/7.6.1?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![confidence](https://developer.mend.io/api/mc/badges/confidence/pypi/coverage/7.6.0/7.6.1?slim=true)](https://docs.renovatebot.com/merge-confidence/) | --- ### Release Notes <details> <summary>nedbat/coveragepy (coverage)</summary> ### [`v7.6.1`](https://togithub.com/nedbat/coveragepy/blob/HEAD/CHANGES.rst#Version-761--2024-08-04) [Compare Source](https://togithub.com/nedbat/coveragepy/compare/7.6.0...7.6.1) - Fix: coverage used to fail when measuring code using :func:`runpy.run_path <python:runpy.run_path>` with a :class:`Path <python:pathlib.Path>` argument. This is now fixed, thanks to `Ask Hjorth Larsen <pull 1819_>`\_. - Fix: backslashes preceding a multi-line backslashed string could confuse the HTML report. This is now fixed, thanks to `LiuYinCarl <pull 1828_>`\_. - Now we publish wheels for Python 3.13, both regular and free-threaded. .. \_pull 1819:[https://github.com/nedbat/coveragepy/pull/1819](https://togithub.com/nedbat/coveragepy/pull/1819)9 .. \_pull 1828[https://github.com/nedbat/coveragepy/pull/1828](https://togithub.com/nedbat/coveragepy/pull/1828)28 .. \_changes\_7-6-0: </details> --- ### Configuration 📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined). 🚦 **Automerge**: Enabled. ♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox. 🔕 **Ignore**: Close this PR and you won't be reminded about this update again. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box --- This PR was generated by [Mend Renovate](https://www.mend.io/free-developer-tools/renovate/). View the [repository job log](https://developer.mend.io/github/rustymotors/server-old). <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNy40NDAuNyIsInVwZGF0ZWRJblZlciI6IjM3LjQ0MC43IiwidGFyZ2V0QnJhbmNoIjoibWFpbiIsImxhYmVscyI6W119-->
[![Mend Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com) This PR contains the following updates: | Package | Change | Age | Adoption | Passing | Confidence | |---|---|---|---|---|---| | [coverage](https://togithub.com/nedbat/coveragepy) | `==7.6.0` -> `==7.6.1` | [![age](https://developer.mend.io/api/mc/badges/age/pypi/coverage/7.6.1?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![adoption](https://developer.mend.io/api/mc/badges/adoption/pypi/coverage/7.6.1?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![passing](https://developer.mend.io/api/mc/badges/compatibility/pypi/coverage/7.6.0/7.6.1?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![confidence](https://developer.mend.io/api/mc/badges/confidence/pypi/coverage/7.6.0/7.6.1?slim=true)](https://docs.renovatebot.com/merge-confidence/) | --- ### Release Notes <details> <summary>nedbat/coveragepy (coverage)</summary> ### [`v7.6.1`](https://togithub.com/nedbat/coveragepy/blob/HEAD/CHANGES.rst#Version-761--2024-08-04) [Compare Source](https://togithub.com/nedbat/coveragepy/compare/7.6.0...7.6.1) - Fix: coverage used to fail when measuring code using :func:`runpy.run_path <python:runpy.run_path>` with a :class:`Path <python:pathlib.Path>` argument. This is now fixed, thanks to `Ask Hjorth Larsen <pull 1819_>`\_. - Fix: backslashes preceding a multi-line backslashed string could confuse the HTML report. This is now fixed, thanks to `LiuYinCarl <pull 1828_>`\_. - Now we publish wheels for Python 3.13, both regular and free-threaded. .. \_pull 1819:[https://github.com/nedbat/coveragepy/pull/1819](https://togithub.com/nedbat/coveragepy/pull/1819)9 .. \_pull 1828[https://github.com/nedbat/coveragepy/pull/1828](https://togithub.com/nedbat/coveragepy/pull/1828)28 .. \_changes\_7-6-0: </details> --- ### Configuration 📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined). 🚦 **Automerge**: Enabled. ♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox. 🔕 **Ignore**: Close this PR and you won't be reminded about this update again. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box --- This PR was generated by [Mend Renovate](https://www.mend.io/free-developer-tools/renovate/). View the [repository job log](https://developer.mend.io/github/allenporter/flux-local). <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNy40NDAuNyIsInVwZGF0ZWRJblZlciI6IjM3LjQ0MC43IiwidGFyZ2V0QnJhbmNoIjoibWFpbiIsImxhYmVscyI6W119--> Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
[![Mend Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com) This PR contains the following updates: | Package | Change | Age | Adoption | Passing | Confidence | |---|---|---|---|---|---| | [test/coverage](https://togithub.com/nedbat/coveragepy) | `==7.6.0` -> `==7.6.1` | [![age](https://developer.mend.io/api/mc/badges/age/pypi/test%2fcoverage/7.6.1?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![adoption](https://developer.mend.io/api/mc/badges/adoption/pypi/test%2fcoverage/7.6.1?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![passing](https://developer.mend.io/api/mc/badges/compatibility/pypi/test%2fcoverage/7.6.0/7.6.1?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![confidence](https://developer.mend.io/api/mc/badges/confidence/pypi/test%2fcoverage/7.6.0/7.6.1?slim=true)](https://docs.renovatebot.com/merge-confidence/) | --- ### Release Notes <details> <summary>nedbat/coveragepy (test/coverage)</summary> ### [`v7.6.1`](https://togithub.com/nedbat/coveragepy/blob/HEAD/CHANGES.rst#Version-761--2024-08-04) [Compare Source](https://togithub.com/nedbat/coveragepy/compare/7.6.0...7.6.1) - Fix: coverage used to fail when measuring code using :func:`runpy.run_path <python:runpy.run_path>` with a :class:`Path <python:pathlib.Path>` argument. This is now fixed, thanks to `Ask Hjorth Larsen <pull 1819_>`\_. - Fix: backslashes preceding a multi-line backslashed string could confuse the HTML report. This is now fixed, thanks to `LiuYinCarl <pull 1828_>`\_. - Now we publish wheels for Python 3.13, both regular and free-threaded. .. \_pull 1819:[https://github.com/nedbat/coveragepy/pull/1819](https://togithub.com/nedbat/coveragepy/pull/1819)9 .. \_pull 1828[https://github.com/nedbat/coveragepy/pull/1828](https://togithub.com/nedbat/coveragepy/pull/1828)28 .. \_changes\_7-6-0: </details> --- ### Configuration 📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined). 🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied. ♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox. 🔕 **Ignore**: Close this PR and you won't be reminded about this update again. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box --- This PR was generated by [Mend Renovate](https://www.mend.io/free-developer-tools/renovate/). View the [repository job log](https://developer.mend.io/github/eduMFA/eduMFA). <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNy40NDAuNyIsInVwZGF0ZWRJblZlciI6IjM3LjQ0MC43IiwidGFyZ2V0QnJhbmNoIjoibWFpbiIsImxhYmVscyI6W119--> Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
[![Mend Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com) This PR contains the following updates: | Package | Type | Update | Change | Age | Adoption | Passing | Confidence | |---|---|---|---|---|---|---|---| | | | lockFileMaintenance | All locks refreshed | | | | | | [black](https://togithub.com/psf/black) ([changelog](https://togithub.com/psf/black/blob/main/CHANGES.md)) | dev | minor | `24.4.2` -> `24.8.0` | [![age](https://developer.mend.io/api/mc/badges/age/pypi/black/24.8.0?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![adoption](https://developer.mend.io/api/mc/badges/adoption/pypi/black/24.8.0?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![passing](https://developer.mend.io/api/mc/badges/compatibility/pypi/black/24.4.2/24.8.0?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![confidence](https://developer.mend.io/api/mc/badges/confidence/pypi/black/24.4.2/24.8.0?slim=true)](https://docs.renovatebot.com/merge-confidence/) | | [coverage](https://togithub.com/nedbat/coveragepy) | dependencies | patch | `7.6.0` -> `7.6.1` | [![age](https://developer.mend.io/api/mc/badges/age/pypi/coverage/7.6.1?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![adoption](https://developer.mend.io/api/mc/badges/adoption/pypi/coverage/7.6.1?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![passing](https://developer.mend.io/api/mc/badges/compatibility/pypi/coverage/7.6.0/7.6.1?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![confidence](https://developer.mend.io/api/mc/badges/confidence/pypi/coverage/7.6.0/7.6.1?slim=true)](https://docs.renovatebot.com/merge-confidence/) | | [ruff](https://docs.astral.sh/ruff) ([source](https://togithub.com/astral-sh/ruff), [changelog](https://togithub.com/astral-sh/ruff/blob/main/CHANGELOG.md)) | dev | patch | `0.5.5` -> `0.5.6` | [![age](https://developer.mend.io/api/mc/badges/age/pypi/ruff/0.5.6?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![adoption](https://developer.mend.io/api/mc/badges/adoption/pypi/ruff/0.5.6?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![passing](https://developer.mend.io/api/mc/badges/compatibility/pypi/ruff/0.5.5/0.5.6?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![confidence](https://developer.mend.io/api/mc/badges/confidence/pypi/ruff/0.5.5/0.5.6?slim=true)](https://docs.renovatebot.com/merge-confidence/) | 🔧 This Pull Request updates lock files to use the latest dependency versions. --- ### Release Notes <details> <summary>psf/black (black)</summary> ### [`v24.8.0`](https://togithub.com/psf/black/blob/HEAD/CHANGES.md#2480) [Compare Source](https://togithub.com/psf/black/compare/24.4.2...24.8.0) ##### Stable style - Fix crash when `# fmt: off` is used before a closing parenthesis or bracket. ([#​4363](https://togithub.com/psf/black/issues/4363)) ##### Packaging - Packaging metadata updated: docs are explictly linked, the issue tracker is now also linked. This improves the PyPI listing for Black. ([#​4345](https://togithub.com/psf/black/issues/4345)) ##### Parser - Fix regression where Black failed to parse a multiline f-string containing another multiline string ([#​4339](https://togithub.com/psf/black/issues/4339)) - Fix regression where Black failed to parse an escaped single quote inside an f-string ([#​4401](https://togithub.com/psf/black/issues/4401)) - Fix bug with Black incorrectly parsing empty lines with a backslash ([#​4343](https://togithub.com/psf/black/issues/4343)) - Fix bugs with Black's tokenizer not handling `\{` inside f-strings very well ([#​4422](https://togithub.com/psf/black/issues/4422)) - Fix incorrect line numbers in the tokenizer for certain tokens within f-strings ([#​4423](https://togithub.com/psf/black/issues/4423)) ##### Performance - Improve performance when a large directory is listed in `.gitignore` ([#​4415](https://togithub.com/psf/black/issues/4415)) ##### *Blackd* - Fix blackd (and all extras installs) for docker container ([#​4357](https://togithub.com/psf/black/issues/4357)) </details> <details> <summary>nedbat/coveragepy (coverage)</summary> ### [`v7.6.1`](https://togithub.com/nedbat/coveragepy/blob/HEAD/CHANGES.rst#Version-761--2024-08-04) [Compare Source](https://togithub.com/nedbat/coveragepy/compare/7.6.0...7.6.1) - Fix: coverage used to fail when measuring code using :func:`runpy.run_path <python:runpy.run_path>` with a :class:`Path <python:pathlib.Path>` argument. This is now fixed, thanks to `Ask Hjorth Larsen <pull 1819_>`\_. - Fix: backslashes preceding a multi-line backslashed string could confuse the HTML report. This is now fixed, thanks to `LiuYinCarl <pull 1828_>`\_. - Now we publish wheels for Python 3.13, both regular and free-threaded. .. \_pull 1819:[https://github.com/nedbat/coveragepy/pull/1819](https://togithub.com/nedbat/coveragepy/pull/1819)9 .. \_pull 1828[https://github.com/nedbat/coveragepy/pull/1828](https://togithub.com/nedbat/coveragepy/pull/1828)28 .. \_changes\_7-6-0: </details> <details> <summary>astral-sh/ruff (ruff)</summary> ### [`v0.5.6`](https://togithub.com/astral-sh/ruff/blob/HEAD/CHANGELOG.md#056) [Compare Source](https://togithub.com/astral-sh/ruff/compare/0.5.5...0.5.6) Ruff 0.5.6 automatically enables linting and formatting of notebooks in *preview mode*. You can opt-out of this behavior by adding `*.ipynb` to the `extend-exclude` setting. ```toml [tool.ruff] extend-exclude = ["*.ipynb"] ``` ##### Preview features - Enable notebooks by default in preview mode ([#​12621](https://togithub.com/astral-sh/ruff/pull/12621)) - \[`flake8-builtins`] Implement import, lambda, and module shadowing ([#​12546](https://togithub.com/astral-sh/ruff/pull/12546)) - \[`pydoclint`] Add `docstring-missing-returns` (`DOC201`) and `docstring-extraneous-returns` (`DOC202`) ([#​12485](https://togithub.com/astral-sh/ruff/pull/12485)) ##### Rule changes - \[`flake8-return`] Exempt cached properties and other property-like decorators from explicit return rule (`RET501`) ([#​12563](https://togithub.com/astral-sh/ruff/pull/12563)) ##### Server - Make server panic hook more error resilient ([#​12610](https://togithub.com/astral-sh/ruff/pull/12610)) - Use `$/logTrace` for server trace logs in Zed and VS Code ([#​12564](https://togithub.com/astral-sh/ruff/pull/12564)) - Keep track of deleted cells for reorder change request ([#​12575](https://togithub.com/astral-sh/ruff/pull/12575)) ##### Configuration - \[`flake8-implicit-str-concat`] Always allow explicit multi-line concatenations when implicit concatenations are banned ([#​12532](https://togithub.com/astral-sh/ruff/pull/12532)) ##### Bug fixes - \[`flake8-async`] Avoid flagging `asyncio.timeout`s as unused when the context manager includes `asyncio.TaskGroup` ([#​12605](https://togithub.com/astral-sh/ruff/pull/12605)) - \[`flake8-slots`] Avoid recommending `__slots__` for classes that inherit from more than `namedtuple` ([#​12531](https://togithub.com/astral-sh/ruff/pull/12531)) - \[`isort`] Avoid marking required imports as unused ([#​12537](https://togithub.com/astral-sh/ruff/pull/12537)) - \[`isort`] Preserve trailing inline comments on import-from statements ([#​12498](https://togithub.com/astral-sh/ruff/pull/12498)) - \[`pycodestyle`] Add newlines before comments (`E305`) ([#​12606](https://togithub.com/astral-sh/ruff/pull/12606)) - \[`pycodestyle`] Don't attach comments with mismatched indents ([#​12604](https://togithub.com/astral-sh/ruff/pull/12604)) - \[`pyflakes`] Fix preview-mode bugs in `F401` when attempting to autofix unused first-party submodule imports in an `__init__.py` file ([#​12569](https://togithub.com/astral-sh/ruff/pull/12569)) - \[`pylint`] Respect start index in `unnecessary-list-index-lookup` ([#​12603](https://togithub.com/astral-sh/ruff/pull/12603)) - \[`pyupgrade`] Avoid recommending no-argument super in `slots=True` dataclasses ([#​12530](https://togithub.com/astral-sh/ruff/pull/12530)) - \[`pyupgrade`] Use colon rather than dot formatting for integer-only types ([#​12534](https://togithub.com/astral-sh/ruff/pull/12534)) - Fix NFKC normalization bug when removing unused imports ([#​12571](https://togithub.com/astral-sh/ruff/pull/12571)) ##### Other changes - Consider more stdlib decorators to be property-like ([#​12583](https://togithub.com/astral-sh/ruff/pull/12583)) - Improve handling of metaclasses in various linter rules ([#​12579](https://togithub.com/astral-sh/ruff/pull/12579)) - Improve consistency between linter rules in determining whether a function is property ([#​12581](https://togithub.com/astral-sh/ruff/pull/12581)) </details> --- ### Configuration 📅 **Schedule**: Branch creation - "before 4am on monday" in timezone America/Los_Angeles, Automerge - At any time (no schedule defined). 🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied. ♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox. 👻 **Immortal**: This PR will be recreated if closed unmerged. Get [config help](https://togithub.com/renovatebot/renovate/discussions) if that's undesired. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box --- This PR was generated by [Mend Renovate](https://www.mend.io/free-developer-tools/renovate/). View the [repository job log](https://developer.mend.io/github/cerebrotech/cucu). <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNy40NDAuNyIsInVwZGF0ZWRJblZlciI6IjM4LjE4LjE3IiwidGFyZ2V0QnJhbmNoIjoibWFpbiIsImxhYmVscyI6W119--> Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
I ran into the following problem where coverage replaces
runpy.run_path()
in a way that does not accept Path objects:This passes with ordinary pytest but crashes with
pytest --cov
with the following traceback:This PR contains a minimal fix which sends the input through
str(Path(...))
. However a proper fix might require some awareness of the surrounding code as well as a test, so I'd expect the PR in its current form to be insufficient. Feedback would be appreciated.