Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor use case and test case in decorators.py #29

Open
maryjess opened this issue Oct 3, 2024 · 0 comments
Open

Refactor use case and test case in decorators.py #29

maryjess opened this issue Oct 3, 2024 · 0 comments
Assignees
Labels

Comments

@maryjess
Copy link
Owner

maryjess commented Oct 3, 2024

  • Setup test files for decorators

tests/test_decorators.py 👉🏻👉🏻 pytest is used here!

# test_decorators.py
import pytest
from decorators import get_input

def test_valid_input(monkeypatch):
    monkeypatch.setattr('builtins.input', lambda _: "25")
    assert get_input("Enter your age: ") == "25"

def test_invalid_input(monkeypatch):
    monkeypatch.setattr('builtins.input', lambda _: "abc")
    with pytest.raises(ValueError):
        get_input("Enter your age: ")
  • tests/test_decorators.py has the unit tests using pytest with monkeypatch to mock the input() function.
This was referenced Oct 3, 2024
@maryjess maryjess self-assigned this Oct 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant