-
-
Notifications
You must be signed in to change notification settings - Fork 428
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://github.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://github.com/nedbat/coveragepy/blob/HEAD/CHANGES.rst#Version-761--2024-08-04) [Compare Source](https://github.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:[nedbat/coveragepy#1819 .. \_pull 1828[nedbat/coveragepy#1828 .. \_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://github.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://github.com/nedbat/coveragepy/blob/HEAD/CHANGES.rst#Version-761--2024-08-04) [Compare Source](https://github.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:[nedbat/coveragepy#1819 .. \_pull 1828[nedbat/coveragepy#1828 .. \_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://github.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://github.com/nedbat/coveragepy/blob/HEAD/CHANGES.rst#Version-761--2024-08-04) [Compare Source](https://github.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:[nedbat/coveragepy#1819 .. \_pull 1828[nedbat/coveragepy#1828 .. \_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>
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.