Skip to content

Increase test coverage for filecmp - #159663

Open
Bolotnyj wants to merge 6 commits into
python:mainfrom
Bolotnyj:feature/filecmp-coverage
Open

Bolotnyj wants to merge 6 commits into
python:mainfrom
Bolotnyj:feature/filecmp-coverage

Conversation

@Bolotnyj

@Bolotnyj Bolotnyj commented Oct 18, 2026 •

Copy link
Copy Markdown

Added new unit tests to improve test coverage for the filecmp module.

Changes:

  • Added test_cache_overflow_and_hit to FileCompareTestCase.
  • Created a new isolated test class DirCmpImplementationTests to test dircmp internals through the public API (without relying on implementation details like phase2 or phase4_closure).
  • Added test_dircmp_os_errors_in_processing to verify OSError handling.
  • Added test_dircmp_different_types_and_funny_types to check type handling behavior.
  • Added test_dircmp_closure_and_report_funnies to verify recursive closure processing and report output.
  • Replaced boilerplate try/finally blocks with standard self.addCleanup() calls for reliable resource cleanups.

@bedevere-app bedevere-app Bot added awaiting review tests Tests in the Lib/test dir labels Oct 18, 2026
@bedevere-app

bedevere-app Bot commented Oct 18, 2026

Copy link
Copy Markdown

Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool.

If this change has little impact on Python users, wait for a maintainer to apply the skip news label instead.

@Bolotnyj Bolotnyj changed the title [skip issue] Increase test coverage for filecmp module skip issue Increase test coverage for filecmp module Oct 18, 2026
@Bolotnyj Bolotnyj changed the title skip issue Increase test coverage for filecmp module skip issue test_filecmp: Increase test coverage for filecmp module Oct 18, 2026
@Bolotnyj Bolotnyj changed the title skip issue test_filecmp: Increase test coverage for filecmp module gh-122409: Increase test coverage for filecmp module Oct 18, 2026
@Bolotnyj Bolotnyj changed the title gh-122409: Increase test coverage for filecmp module gh-122410: Increase test coverage for filecmp module Oct 18, 2026
@Bolotnyj Bolotnyj changed the title gh-122410: Increase test coverage for filecmp module skip issue test_filecmp: Increase test coverage for filecmp module Oct 18, 2026
@Bolotnyj Bolotnyj changed the title skip issue test_filecmp: Increase test coverage for filecmp module test_filecmp: Increase test coverage for filecmp module Oct 18, 2026
@picnixz

picnixz commented Oct 19, 2026

Copy link
Copy Markdown
Member

Please don't just change the issue title. Simply wait for a maintainer to add corresponding labels if necessary.

@@ -0,0 +1 @@
Added new unit tests to improve test coverage for the filecmp module.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

There is no need for that NEWS entry.

@picnixz picnixz left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

  • Don't put the tests just after the setUp() method, it doesn't make sense. Please be more mindful of existing code.
  • What are we exactly testing and for which reason exactly as well? phase2() looks like a private (despite its public name) method which doesn't make sense to test specifically (it's not documented in https://docs.python.org/3/library/filecmp.html).
  • Are we simply testing incomplete findings that only occur in phase2()? we usually don't test implementation details like that though.
  • A lot of your tests seem to share a common setup. Why not extending setUp() or simply create a new class just for testing phase2?

Comment thread Lib/test/test_filecmp.py Outdated
if os.path.exists(d_path):
os.rmdir(d_path)

def test_dircmp_invalid_attribute_error(self):

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why should we add this test? it's a useless test IMO.

Comment thread Lib/test/test_filecmp.py Outdated
Comment on lines +163 to +172
try:
with patch("os.stat", side_effect=fake_stat):
dc = filecmp.dircmp(self.dir, self.dir_same)
dc.phase2()
self.assertIn(trigger_file, dc.common_funny)
finally:
for d in (self.dir, self.dir_same):
p = os.path.join(d, trigger_file)
if os.path.exists(p):
os.remove(p)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Use self.addCleanup and a shutil.rmtree call.

Comment thread Lib/test/test_filecmp.py Outdated

self.assertIn(file_diff_type, dc.common_funny)
self.assertIn(file_funny_type, dc.common_funny)
finally:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

likewise

@bedevere-app

bedevere-app Bot commented Oct 19, 2026

Copy link
Copy Markdown

A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated.

Once you have made the requested changes, please leave a comment on this pull request containing the phrase I have made the requested changes; please review again. I will then notify any core developers who have left a review that you're ready for them to take another look at this pull request.

@picnixz picnixz changed the title test_filecmp: Increase test coverage for filecmp module Increase test coverage for filecmp module Oct 19, 2026
@picnixz picnixz changed the title Increase test coverage for filecmp module Increase test coverage for filecmp Oct 19, 2026
@Bolotnyj

Copy link
Copy Markdown
Author

Picnixz, I have taken your words into account and will correct the errors.

@Bolotnyj

Copy link
Copy Markdown
Author

I have made the requested changes; please review again.

@bedevere-app

bedevere-app Bot commented Oct 21, 2026

Copy link
Copy Markdown

Thanks for making the requested changes!

@picnixz: please review the changes made to this pull request.

@bedevere-app
bedevere-app Bot requested a review from picnixz October 21, 2026 10:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants