GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — gh-60283: Check for redefined test names in CI by hugovk · Pull Request #109161 · python/cpython

Conversation

@hugovk

@hugovk hugovk commented Sep 8, 2023 •
edited by bedevere-bot
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

Fixes python/core-workflow#505.
Fixes #60283.

Add Ruff to the CI (via pre-commit) to check Lib/test/ for F811 "Redefinition of unused name". Ruff (47s) is faster than Flake8 (1m39s).

This will help find copy/pasted test_* method names, which results in one of them not being run.

It also finds redefined variables, which ISTR people were in favour of.

There are some files which fail to lint or parse, and have been excluded. Some of these are intentional and should never be checked (e.g. Lib/test/badsyntax_pep3120.py), some are due to new 3.12+ syntax not yet supported by the Ruff linter (e.g. Lib/test/test_type_aliases.py). I think we can be pragmatic and exclude any that add new syntax until such a time the linter supports the new version. (This may also help drive adoption of new syntax by the linter.)

This currently fails due to duplicated tests in test_monitoring, which will be fixed in #109139 and has been left as a demonstration in the meantime.

All other test_* duplicates have been fixed (see links in python/core-workflow#505).

Some files have duplicate variables, I've excluded those and they can be fixed and re-included in the future.

  • Issue: list duplicate test names with patchcheck #60283

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

erlend-aasland reacted with rocket emoji
All reactions
  • 🚀 1 reaction
hugovk added 2 commits September 8, 2023 17:37
@hugovk
Check for redefined names in CI
4cd4803
@hugovk
Temporarily exclude files with: F811 Redefinition of unused name
a37828c
@hugovk
hugovk requested a review from AlexWaygood as a code owner September 8, 2023 20:49
@bedevere-bot bedevere-bot added the awaiting core review label Sep 8, 2023
@hugovk
hugovk marked this pull request as draft September 8, 2023 20:49
@bedevere-bot bedevere-bot mentioned this pull request Sep 8, 2023
list duplicate test names with patchcheck #60283
Closed
@bedevere-bot bedevere-bot removed the awaiting core review label Sep 8, 2023
@hugovk hugovk added awaiting core review skip news tests Tests in the Lib/test dir labels Sep 8, 2023
@hugovk hugovk mentioned this pull request Sep 8, 2023
Detect duplicate method names in CI python/core-workflow#505
Closed
AlexWaygood
AlexWaygood reviewed Sep 8, 2023
View reviewed changes
Comment thread .ruff.toml Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread .pre-commit-config.yaml Resolved

Uh oh!

There was an error while loading. Please reload this page.

@hugovk
Move Ruff config file to relevant subdirectory to localise rules
0dcdd08
AlexWaygood
AlexWaygood reviewed Sep 9, 2023
View reviewed changes
Comment thread Lib/test/.ruff.toml Resolved

Uh oh!

There was an error while loading. Please reload this page.

hugovk and others added 2 commits September 9, 2023 06:22
@hugovk @AlexWaygood
Comment the rule
d14c002
Co-authored-by: Alex Waygood <[email protected]>
@hugovk
Move autofix setting from pre-commit to Ruff config
cb8237c
AlexWaygood
AlexWaygood approved these changes Sep 9, 2023
View reviewed changes

@AlexWaygood AlexWaygood left a comment

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks! I guess we just have to wait for #109139 to be merged first?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@bedevere-bot bedevere-bot added awaiting merge and removed awaiting core review labels Sep 9, 2023
AA-Turner
AA-Turner reviewed Sep 9, 2023
View reviewed changes
Comment thread .pre-commit-config.yaml Resolved

Uh oh!

There was an error while loading. Please reload this page.

hugovk added 3 commits September 10, 2023 13:54
@hugovk
Show diff and add annotations
1bdae72
@hugovk
Re-order args
83904af
@hugovk
Remove --diff
8fd293a
@hugovk

hugovk commented Sep 10, 2023

Copy link
Copy Markdown
Member Author

Should we have changes to .pre-commit-config.yaml and .ruff.toml NOT trigger the main test build?

That would mean adding to this grep pattern:

cpython/.github/workflows/build.yml

Line 66 in 2dd6a86

git diff --name-only origin/$GITHUB_BASE_REF.. | grep -qvE '(\.rst$|^Doc|^Misc)' && echo "run_tests=true" >> $GITHUB_OUTPUT || true

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@AlexWaygood

AlexWaygood commented Sep 10, 2023

Copy link
Copy Markdown
Member

Should we have changes to .pre-commit-config.yaml and .ruff.toml NOT trigger the main test build?

That sounds like a good idea to me!

hugovk reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

hugovk added 3 commits September 10, 2023 14:56
@hugovk
Update config
66e1172
@hugovk
Don't validate intentionally invalid TOML
9b1b43a
@hugovk
Let tomllib look after its own test files
3839aea
AlexWaygood
AlexWaygood reviewed Sep 10, 2023
View reviewed changes
Comment thread .pre-commit-config.yaml Resolved

Uh oh!

There was an error while loading. Please reload this page.

@hugovk @AlexWaygood
Clarify job scope
0bf3e3e
Co-authored-by: Alex Waygood <[email protected]>
@hugovk
hugovk requested a review from ezio-melotti as a code owner September 12, 2023 14:45
@bedevere-app bedevere-app Bot added awaiting review and removed awaiting merge labels Sep 12, 2023
@hugovk
hugovk enabled auto-merge (squash) September 12, 2023 14:49
@hugovk hugovk added triaged The issue has been accepted as valid by a triager. and removed triaged The issue has been accepted as valid by a triager. labels Sep 12, 2023
@hugovk
hugovk merged commit 3cb9a8e into python:main Sep 12, 2023
@hugovk
hugovk deleted the pre-commit-ruff-F811 branch September 12, 2023 15:28
@bedevere-app bedevere-app Bot removed the awaiting review label Sep 12, 2023
@AlexWaygood

AlexWaygood commented Sep 12, 2023

Copy link
Copy Markdown
Member

🥳

hugovk and AA-Turner reacted with hooray emoji
All reactions
  • 🎉 2 reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@hugovk hugovk added needs backport to 3.11 only security fixes needs backport to 3.12 only security fixes labels Sep 13, 2023
@miss-islington

miss-islington commented Sep 13, 2023

Copy link
Copy Markdown
Contributor

Thanks @hugovk for the PR 🌮🎉.. I'm working now to backport this PR to: 3.12.
🐍🍒⛏🤖

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@miss-islington

miss-islington commented Sep 13, 2023

Copy link
Copy Markdown
Contributor

Thanks @hugovk for the PR 🌮🎉.. I'm working now to backport this PR to: 3.11.
🐍🍒⛏🤖

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@miss-islington

miss-islington commented Sep 13, 2023

Copy link
Copy Markdown
Contributor

Sorry, @hugovk, I could not cleanly backport this to 3.11 due to a conflict.
Please backport using cherry_picker on command line.
cherry_picker 3cb9a8edca6e3fa0f0045b03a9a6444cf8f7affe 3.11

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Sep 13, 2023
@hugovk @AlexWaygood
@AA-Turner @miss-islington
pythongh-60283: Check for redefined test names in CI (pythonGH-109161)
50edeff
(cherry picked from commit 3cb9a8e)

Co-authored-by: Hugo van Kemenade <[email protected]>
Co-authored-by: Alex Waygood <[email protected]>
Co-authored-by: Adam Turner <[email protected]>
@miss-islington miss-islington assigned hugovk Sep 13, 2023
@bedevere-app

bedevere-app Bot commented Sep 13, 2023

Copy link
Copy Markdown

GH-109365 is a backport of this pull request to the 3.12 branch.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bedevere-app bedevere-app Bot removed the needs backport to 3.12 only security fixes label Sep 13, 2023
hugovk added a commit to hugovk/cpython that referenced this pull request Sep 13, 2023
@hugovk @AlexWaygood @AA-Turner
pythongh-60283: Check for redefined test names in CI (python#109161)
27d63e6
Co-authored-by: Alex Waygood <[email protected]>
Co-authored-by: Adam Turner <[email protected]>
(cherry picked from commit 3cb9a8e)
@bedevere-app

bedevere-app Bot commented Sep 13, 2023

Copy link
Copy Markdown

GH-109366 is a backport of this pull request to the 3.11 branch.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bedevere-app bedevere-app Bot removed the needs backport to 3.11 only security fixes label Sep 13, 2023
@hugovk

hugovk commented Sep 13, 2023

Copy link
Copy Markdown
Member Author

For the backport PRs, I updated the exclude lists, as they were slightly different.

And interestingly, we don't need to explicitly exclude the "Failed to lint/parse" files because they're printed to screen but don't fail the command.

For example, these all have return code = 0 = success:

❯ pre-commit run --all-files ruff
Run Ruff on Lib/test/....................................................Passed
❯ pre-commit run --all-files ruff --verbose
Run Ruff on Lib/test/....................................................Passed
- hook id: ruff
- duration: 0.02s

error: Failed to parse Lib/test/tokenizedata/badsyntax_3131.py:2:1: Got unexpected token €
error: Failed to parse Lib/test/test_fstring.py:671:28: f-string: expecting '}'
warning: Failed to lint Lib/test/badsyntax_pep3120.py: stream did not contain valid UTF-8
warning: Failed to lint Lib/test/encoded_modules/module_koi8_r.py: stream did not contain valid UTF-8
warning: Failed to lint Lib/test/encoded_modules/module_iso_8859_1.py: stream did not contain valid UTF-8
error: Failed to parse Lib/test/support/socket_helper.py:300:33: f-string: expecting '}'
❯ ruff Lib/test
warning: Failed to lint Lib/test/encoded_modules/module_iso_8859_1.py: stream did not contain valid UTF-8
warning: Failed to lint Lib/test/encoded_modules/module_koi8_r.py: stream did not contain valid UTF-8
warning: Failed to lint Lib/test/badsyntax_pep3120.py: stream did not contain valid UTF-8
error: Failed to parse Lib/test/support/socket_helper.py:300:33: f-string: expecting '}'
error: Failed to parse Lib/test/test_fstring.py:671:28: f-string: expecting '}'
error: Failed to parse Lib/test/tokenizedata/badsyntax_3131.py:2:1: Got unexpected token €

Shall we explicitly exclude them (which makes the verbose output cleaner, and in which case I'll update the backports) or keep the default behaviour (in which case I'll update main)?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@AlexWaygood

AlexWaygood commented Sep 13, 2023

Copy link
Copy Markdown
Member

I think it's better to explicitly exclude the unlintable files, as we do on main. It's maybe slightly harder to maintain, but the improvement in UI is worth it if contributors don't see all those warnings printed to the terminal 👍

hugovk reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@erlend-aasland

erlend-aasland commented Sep 13, 2023

Copy link
Copy Markdown
Contributor

Thanks for doing this!

hugovk reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

vstinner pushed a commit to vstinner/cpython that referenced this pull request Sep 13, 2023
@hugovk @AlexWaygood
@AA-Turner @vstinner
pythongh-60283: Check for redefined test names in CI (python#109161)
c17f5a3
Co-authored-by: Alex Waygood <[email protected]>
Co-authored-by: Adam Turner <[email protected]>
Yhg1s pushed a commit that referenced this pull request Sep 14, 2023
@miss-islington @hugovk
@AlexWaygood @AA-Turner
[3.12] gh-60283: Check for redefined test names in CI (GH-109161) (#1…
36d6ba0
…09365)

* gh-60283: Check for redefined test names in CI (GH-109161)
(cherry picked from commit 3cb9a8e)

Co-authored-by: Hugo van Kemenade <[email protected]>
Co-authored-by: Alex Waygood <[email protected]>
Co-authored-by: Adam Turner <[email protected]>

* Update exclude list for 3.12

* Explicitly exclude files which failed to lint/parse

* Sort to avoid future merge conflicts

---------

Co-authored-by: Hugo van Kemenade <[email protected]>
Co-authored-by: Alex Waygood <[email protected]>
Co-authored-by: Adam Turner <[email protected]>
hugovk added a commit that referenced this pull request Sep 15, 2023
@hugovk @AlexWaygood @AA-Turner
[3.11] gh-60283: Check for redefined test names in CI (#109161) (#109366
a95d159
)

Co-authored-by: Alex Waygood <[email protected]>
Co-authored-by: Adam Turner <[email protected]>
(cherry picked from commit 3cb9a8e)
@AlexWaygood AlexWaygood mentioned this pull request Oct 9, 2023
Run ruff on Argument Clinic in CI #110558
Closed
@AA-Turner AA-Turner mentioned this pull request Feb 3, 2025
Convert change detection to a Python script #129627
Merged
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@AA-Turner AA-Turner AA-Turner approved these changes
@AlexWaygood AlexWaygood AlexWaygood approved these changes
@ezio-melotti ezio-melotti Awaiting requested review from ezio-melotti ezio-melotti is a code owner

Uh oh!

There was an error while loading. Please reload this page.

Assignees

@hugovk hugovk

Labels

skip news tests Tests in the Lib/test dir

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Detect duplicate method names in CI list duplicate test names with patchcheck

Uh oh!

There was an error while loading. Please reload this page.

6 participants

@hugovk @AlexWaygood @miss-islington @erlend-aasland @AA-Turner @bedevere-bot
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.