Python Forum
unittest.assertEqual giving failure on result although it's ok.
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
unittest.assertEqual giving failure on result although it's ok.
#2
you want to compare annual_salary attribute, not the object itself

self.assertEqual(self.employee_one.annual_salary, 505000)
also in the Employee.give_raise() method there is line 11 int(raise_amount). Effectivelly it will do nothing because you don't assign the converted value
By the way, in your give_raise method you don't need the if else block.
If the user does not supply raise_amount, the default value will be used. i.e. if raise_amount will always be True, unless user does not supply something like None. But you don't try to validate the input so you will just end up with exception. In other words at the moment else part will not be executed even if user does not supply explicitly raise_amount

def give_raise(self, raise_amount=5000):
    """Adds a number to the employee annual salary."""
    self.annual_salary += raise_amount
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply


Messages In This Thread
RE: unittest.assertEqual giving failure on result although it's ok. - by buran - Feb-16-2019, 10:17 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  problem in using unittest akbarza 2 379 Feb-25-2024, 12:51 PM
Last Post: deanhystad
  Failure to run source command middlestudent 2 751 Sep-22-2023, 01:21 PM
Last Post: buran
Question Unwanted execution of unittest ThomasFab 9 2,160 Nov-15-2022, 05:33 PM
Last Post: snippsat
  Dickey Fuller failure Led_Zeppelin 4 2,701 Sep-15-2022, 09:07 PM
Last Post: Led_Zeppelin
  unittest.mock for an api key silver 3 1,429 Aug-29-2022, 03:52 PM
Last Post: ndc85430
  Ran 0 tests in 0.000s - unittest Peaches 8 5,279 Dec-31-2021, 08:58 AM
Last Post: Peaches
  Assert failure jtcostel 1 1,672 Sep-03-2021, 05:28 PM
Last Post: buran
Sad Problem with Unittest mhanusek 1 3,837 Nov-12-2020, 04:58 PM
Last Post: Gribouillis
  Unittest et patch mad31 2 2,162 Aug-09-2020, 06:16 AM
Last Post: mad31
  Unusual things to do with unittest/HTMLTestRunner AndyHolyer 0 2,166 Jul-29-2020, 02:43 PM
Last Post: AndyHolyer

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020