Skip to content

Conversation

@gjbex
Copy link
Owner

@gjbex gjbex commented Jan 14, 2025

Summary by Sourcery

Introduce examples for using custom markers and parameterized tests with pytest.

Tests:

  • Add examples of using custom markers with pytest to selectively run tests.
  • Add examples of using parameterized tests with pytest.

@sourcery-ai
Copy link

sourcery-ai bot commented Jan 14, 2025

Reviewer's Guide by Sourcery

This pull request replaces the unit test implementation with pytest. It also introduces custom markers and parameterization to the tests.

Sequence diagram for parameterized test execution

sequenceDiagram
    participant P as Pytest Runner
    participant T as Test Function
    participant F as Fibonacci Function
    loop For each test parameter
        P->>T: Run test with parameter
        T->>F: Call fib(n)
        F-->>T: Return result
        T-->>P: Assert result matches expected
    end
Loading

Class diagram for Fibonacci implementation with test structure

classDiagram
    class fibonacci {
        +fib(n: int): int
    }
    class test_fib {
        +test_negative_input()
        +test_base_cases()
        +test_recursive_case()
    }
    note for test_fib "Tests can be marked with @pytest.mark.slow"
    test_fib ..> fibonacci : tests
Loading

File-Level Changes

Change Details Files
Replaced unittest with pytest for testing the Fibonacci sequence implementation.
  • Added new pytest files for testing Fibonacci sequence.
  • Removed old unittest files.
  • Implemented test cases using pytest's assert statements.
  • Used pytest fixtures for setup and teardown (if applicable).
source-code/testing/PyTest/README.md
source-code/testing/PyTest/CustomMarkers/test_fib.py
source-code/testing/PyTest/Parametrize/test_fib.py
Introduced custom markers for selective test execution.
  • Defined custom markers in pytest.ini.
  • Used markers in test functions to categorize tests (e.g., @pytest.mark.slow).
  • Added documentation explaining how to use custom markers for running tests selectively (e.g., using pytest -m "not slow").
source-code/testing/PyTest/README.md
source-code/testing/PyTest/CustomMarkers/README.md
source-code/testing/PyTest/CustomMarkers/test_fib.py
source-code/testing/PyTest/CustomMarkers/pytest.ini
Implemented parameterized tests for the Fibonacci function.
  • Used @pytest.mark.parametrize to run tests with different input values.
  • Defined test cases with expected outputs for various inputs.
  • Added documentation on how to use parameterized tests with pytest.
  • Ensured that parameterized tests cover a range of input values, including edge cases (if applicable).
source-code/testing/PyTest/README.md
source-code/testing/PyTest/Parametrize/README.md
source-code/testing/PyTest/Parametrize/test_fib.py
source-code/testing/PyTest/Parametrize/pytest.ini
Fixed a typo in typing/README.md.
  • Corrected "introducd" to "introduced" in the description of Python 3.5's type annotations feature in typing/README.md
source-code/typing/README.md

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time. You can also use
    this command to specify where the summary should be inserted.

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@gjbex gjbex merged commit c83f537 into master Jan 14, 2025
Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey @gjbex - I've reviewed your changes and they look great!

Here's what I looked at during the review
  • 🟡 General issues: 3 issues found
  • 🟢 Security: all looks good
  • 🟢 Testing: all looks good
  • 🟢 Complexity: all looks good
  • 🟢 Documentation: all looks good

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.


def fib(n):
if n < 0:
raise ValueError('fac argument must be positive')
Copy link

Choose a reason for hiding this comment

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

issue (typo): Error message refers to 'fac argument' but this is a Fibonacci function

This appears to be a copy-paste error. Consider changing to 'fibonacci argument' or simply 'n' for clarity.

Suggested change
raise ValueError('fac argument must be positive')
raise ValueError('fibonacci argument must be positive')

if __name__ == '__main__':
from argparse import ArgumentParser
arg_parser = ArgumentParser(description='compute fibonacci numbers')
arg_parser.add_argument('n', type=int, default=5,
Copy link

Choose a reason for hiding this comment

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

issue (bug_risk): Default value won't work for positional argument

The default parameter has no effect on positional arguments. Consider using an optional argument (--n) if a default value is needed.

# Typing

Python 3.5 introducd optional type annotation for functions, and that
Python 3.5 introduced optional type annotation for functions, and that
Copy link

Choose a reason for hiding this comment

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

issue (typo): Typo: "introducd" should be "introduced".

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.

2 participants