Skip to content

Conversation

@seer-by-sentry
Copy link

This PR adds tests for #23

Commits:

  • Add unit test for add2 function to cover NameError from undefined variable z
  • Add unit test for add2 function to cover NameError from undefined variable z

@rohitvinnakota-codecov
Copy link
Owner

On it! We are reviewing the PR and will provide feedback shortly.

Comment on lines +33 to +37
def test_add2():
# Test that add2 function raises NameError due to undefined variable 'z'
with pytest.raises(NameError, match="name 'z' is not defined"):
Calculator.add2(1, 2)
Calculator.add2(0, 0)

Choose a reason for hiding this comment

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

The test is attempting to call Calculator.add2(), but this method does not exist in the Calculator class. This will result in an AttributeError: type object 'Calculator' has no attribute 'add2' instead of the expected NameError. The test should either be updated to test an existing method that contains an undefined variable, or the corresponding add2 method should be implemented in the Calculator class first.

Suggested change
def test_add2():
# Test that add2 function raises NameError due to undefined variable 'z'
with pytest.raises(NameError, match="name 'z' is not defined"):
Calculator.add2(1, 2)
Calculator.add2(0, 0)
# First implement the add2 method in Calculator class, or update this test to use an existing method
# Example if add2 method exists:
# def test_add2():
# with pytest.raises(NameError, match="name 'z' is not defined"):
# Calculator.add2(1, 2)

Did we get this right? 👍 / 👎 to inform future reviews.

Choose a reason for hiding this comment

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

hmmm

Choose a reason for hiding this comment

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

Actually in our team, we put all functions in a utils.py file

@rohitvinnakota-codecov
Copy link
Owner

@sentry review

@seer-by-sentry

This comment has been minimized.

@rohitvinnakota-codecov
Copy link
Owner

@sentry review

@seer-by-sentry

This comment has been minimized.

@rohitvinnakota-codecov
Copy link
Owner

@sentry review

@seer-by-sentry

This comment has been minimized.

@rohitvinnakota-codecov
Copy link
Owner

@sentry review

@seer-by-sentry

This comment has been minimized.

@rohitvinnakota-codecov
Copy link
Owner

@sentry review

@seer-by-sentry

This comment has been minimized.

@rohitvinnakota-codecov
Copy link
Owner

@sentry review

@seer-by-sentry

This comment has been minimized.

@rohitvinnakota-codecov
Copy link
Owner

@sentry review

@rohitvinnakota-codecov
Copy link
Owner

@sentry review

@seer-by-sentry

This comment has been minimized.

@rohitvinnakota-codecov
Copy link
Owner

@sentry review

1 similar comment
@rohitvinnakota-codecov
Copy link
Owner

@sentry review

@seer-by-sentry

This comment has been minimized.

@rohitvinnakota-codecov
Copy link
Owner

@sentry review

1 similar comment
@rohitvinnakota-codecov
Copy link
Owner

@sentry review

@seer-by-sentry

This comment has been minimized.

@rohitvinnakota-codecov
Copy link
Owner

@sentry review

@rohitvinnakota-codecov
Copy link
Owner

@codecov-ai-reviewer review

@codecov-ai

This comment has been minimized.

Comment on lines +33 to +37
def test_add2():
# Test that add2 function raises NameError due to undefined variable 'z'
with pytest.raises(NameError, match="name 'z' is not defined"):
Calculator.add2(1, 2)
Calculator.add2(0, 0)
Copy link

Choose a reason for hiding this comment

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

The test test_add2() is attempting to test a method Calculator.add2() that doesn't exist in the Calculator class. Based on the calculator.py file, there is no add2 method defined. This test will fail with an AttributeError because the method doesn't exist, not a NameError as expected. You should either:

  1. Implement the add2 method in the Calculator class if it's intended functionality
  2. Remove this test if it's not needed
  3. Fix the test to call an existing method if this was a typo
Suggested change
def test_add2():
# Test that add2 function raises NameError due to undefined variable 'z'
with pytest.raises(NameError, match="name 'z' is not defined"):
Calculator.add2(1, 2)
Calculator.add2(0, 0)
# If you intended to test the existing 'add' method:
def test_add2():
# Test additional scenarios for the add function
assert Calculator.add(5, 7) == 12
assert Calculator.add(-1, 1) == 0
assert Calculator.add(0.5, 0.5) == 1.0

Did we get this right? 👍 / 👎 to inform future reviews.

Comment on lines +34 to +35
# Test that add2 function raises NameError due to undefined variable 'z'
with pytest.raises(NameError, match="name 'z' is not defined"):
Copy link

Choose a reason for hiding this comment

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

The test expects a NameError with the message "name 'z' is not defined", but this doesn't make sense in the context of testing a calculator method. This suggests the test is either:

  1. Testing some internal implementation detail that references an undefined variable 'z'
  2. Copy-pasted from another context
  3. Not properly designed for the intended functionality

Tests should focus on the public API and expected behavior, not internal implementation errors.

Suggested change
# Test that add2 function raises NameError due to undefined variable 'z'
with pytest.raises(NameError, match="name 'z' is not defined"):
# Test should focus on expected behavior, for example:
# with pytest.raises(TypeError, match="missing 1 required positional argument"):
# Calculator.add(1) # Missing second argument

Did we get this right? 👍 / 👎 to inform future reviews.

@rohitvinnakota-codecov
Copy link
Owner

@sentry review

Comment on lines +33 to +36
def test_add2():
# Test that add2 function raises NameError due to undefined variable 'z'
with pytest.raises(NameError, match="name 'z' is not defined"):
Calculator.add2(1, 2)
Copy link
Author

Choose a reason for hiding this comment

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

The test is attempting to call Calculator.add2() which doesn't exist in the Calculator class. Based on the calculator.py file, there is no add2 method defined. This test will fail with an AttributeError before it can test for the expected NameError. Either implement the add2 method in the Calculator class or remove this test if it's not needed.

Suggested change
def test_add2():
# Test that add2 function raises NameError due to undefined variable 'z'
with pytest.raises(NameError, match="name 'z' is not defined"):
Calculator.add2(1, 2)
# Either implement Calculator.add2() method or remove this test
# If testing error handling, ensure the method exists first

Did we get this right? 👍 / 👎 to inform future reviews.

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