Skip to content

Conversation

@miquelbeltran
Copy link
Contributor

@miquelbeltran miquelbeltran commented May 5, 2025

Description 📝

Purpose:

This PR fixes all the static analysis errors found using flake8.

Approach:

Several runs running flake8 and the unit tests to ensure all works correctly.

During the process, I found out that some tests were not executed because a test class name was duplicated. The static analysis tool helped find that.

Type of change

  • fix: Bug fix (non-breaking change which fixes an issue)
  • feat: New feature (non-breaking change which adds functionality)
  • chore: Chore task, release or small impact change
  • ci: CI configuration change
  • Other type of change (specify)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

Updates

Most static analysis errors are fixed, some are ignored because they are necessary for clarity or for the provider to work.

Some tests required fixes as well.

Related issues

Continues work in #112

Test plan 🧪

  • Run tests localy.

Author to check 👓

  • Project and all contained modules builds successfully
  • Self-/dev-tested
  • Unit/UI/Automation/Integration tests provided where applicable
  • Code is written to standards
  • Appropriate documentation written (code comments, internal docs)

Reviewer to check ✔️

  • Project and all contained modules builds successfully
  • Change has been dev-/reviewer-tested, where possible
  • Unit/UI/Automation/Integration tests provided where applicable
  • Code is written to standards
  • Appropriate documentation written (code comments, internal docs)

@miquelbeltran miquelbeltran marked this pull request as draft May 5, 2025 08:07
@miquelbeltran miquelbeltran marked this pull request as ready for review May 5, 2025 08:31
push:
branches: [ master ]
pull_request:
branches: [ master ]
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed this rule, so it allows to run this CI workflow on PRs that don't target master.

Copy link
Contributor

Choose a reason for hiding this comment

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

Fair call


try:
import ssl
import ssl # noqa: F401
Copy link
Contributor Author

Choose a reason for hiding this comment

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

F401 = unused import

Copy link
Contributor

Choose a reason for hiding this comment

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

Add as a comment to cover for documentation ^

Comment on lines +4 to +6
import sys
import logging
import os
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The static analysis tool enforces one import per line

Copy link
Contributor

Choose a reason for hiding this comment

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

That's fine 👍🏽


try:
foo = "bar"
foo = "bar" # noqa: F841
Copy link
Contributor Author

Choose a reason for hiding this comment

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

F841 = unused variable

Copy link
Contributor

Choose a reason for hiding this comment

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

Remove this in that case or add as comment for documentation?

except Exception:
result = client.send_exception(httpRequest={})

self.assertEqual(result[0], 202)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This assert was missing in the original test



class TestRaygunErrorMessage(unittest.TestCase):
class TestRaygunErrorMessageChained(unittest.TestCase):
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This class name was duplicated, which caused that the above tests were ignored. This was detected thanks to the static analysis tool.

Copy link

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

This PR refactors the codebase to fix static analysis errors reported by flake8. The changes primarily update exception handling to be explicit (using "except Exception:" instead of bare except clauses), remove unused imports, and add noqa comments for unused variable assignments.

  • Refactored exception handling in tests and production code.
  • Removed unused imports and added "# noqa" annotations where needed.
  • Updated CI workflow to re-enable flake8 linting.

Reviewed Changes

Copilot reviewed 9 out of 10 changed files in this pull request and generated no comments.

Show a summary per file
File Description
python3/tests/test_utilities.py Removed unnecessary imports to satisfy flake8.
python3/tests/test_raygunprovider.py Changed exception handling to be explicit.
python3/tests/test_raygunmsgs.py Updated exception handling and renamed test class for chaining.
python3/tests/test_functional.py Replaced bare except clauses and added noqa comments for unused assignments.
python3/samples/sample.py Updated exception handling to be explicit.
python3/raygun4py/raygunprovider.py Added "# noqa: F401" to the ssl import to address static analysis.
python3/raygun4py/raygunmsgs.py Refactored exception handling and string formatting in warning messages.
python3/raygun4py/init.py Added "# noqa: F401" to suppress unused import warnings.
.github/workflows/python-checks.yml Re-enabled flake8 linting by uncommenting the linting step.
Files not reviewed (1)
  • .flake8: Language not supported
Comments suppressed due to low confidence (1)

python3/tests/test_raygunmsgs.py:240

  • The variable 'msg_clone' is used in place of 'msg', but it does not appear to be defined in this context. Verify if 'msg_clone' was intended or if this should be reverted to 'msg'.
self.find_local_variable(msg_clone.stackTrace, "localReference"),

Copy link
Contributor

@sumitramanga sumitramanga left a comment

Choose a reason for hiding this comment

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

Looks good, nothing major stands out here 😃

@miquelbeltran miquelbeltran changed the base branch from github-ci-setup to master May 8, 2025 05:12
@miquelbeltran miquelbeltran merged commit f3dd23d into master May 8, 2025
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants