Skip to content

Fix: ResourceWarning on python 3.12 and remove deprecated usage of codecs#1314

Merged
bittner merged 2 commits intobehave:mainfrom
joaoMiraya:fix/resource-warning
Apr 16, 2026
Merged

Fix: ResourceWarning on python 3.12 and remove deprecated usage of codecs#1314
bittner merged 2 commits intobehave:mainfrom
joaoMiraya:fix/resource-warning

Conversation

@joaoMiraya
Copy link
Copy Markdown
Contributor

@joaoMiraya joaoMiraya commented Mar 25, 2026

JUnitReporter.feature() opens the XML output file with codecs.open() but never
closes it. This causes a ResourceWarning on Python 3.12+ and will break on Python 3.14,
where codecs.open() is deprecated.

This PR fixes both issues with a one-line change.

Issue

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Fixes a Python 3.12+ ResourceWarning (and Python 3.14 deprecation risk) in JUnitReporter.feature() by ensuring the JUnit XML output file is properly closed and by removing deprecated codecs.open() usage.

Changes:

  • Remove the unused/deprecated codecs import.
  • Write JUnit XML using a with open(..., "wb") context manager to ensure deterministic file closure.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread behave/reporter/junit.py
Verifies that JUnitReporter.feature() deterministically closes the report
file handle (no ResourceWarning) and writes valid XML output.

This test was added for PR behave#1314.
@bittner bittner self-assigned this Apr 16, 2026
@bittner bittner merged commit 9355696 into behave:main Apr 16, 2026
@bittner
Copy link
Copy Markdown
Member

bittner commented Apr 16, 2026

Thank you and your agent! 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix: JUnitReporter leaves XML file unclosed, causing ResourceWarning on Python 3.12

3 participants