python - AssertionError when trying to assert return value from two dictionaries with py.test -


i'm testing text-based game i've been making learn python. last few days have been busy finding solution problem keep encountering. have tried multiple test methods, end giving me same error.

the problem following assertionerror (using py.test):

 e       assertionerror: assert <textgame.waffle.winefields object @ 0x03bdecd0> ==   <textgame.waffle.winefields object @ 0x03bd00d0> 

obviously, object (textgame.waffle.winefields) correct, location different. don't care location. assume because i'm using 2 separate dictionaries same contents. however, prefer keep using dictionary if possible.

the minimal working example of test looks follows:

import textgame.waffle  def test_change_map():      roomnames = {         "the wine fields" : textgame.waffle.winefields(),     }      room = "the wine fields"     next_room = roomnames[room]      assert textgame.waffle.map(room).change(room) == next_room 

the textgame.waffle game i'm trying assert looks this:

class winefields(object):     pass  class map(object):      roomnames = {         'the wine fields': winefields(),     }      def __init__(self, next_one):         self.next_one = next_one      def change(self, next_one):         return map.roomnames[next_one] 

i have tried methods solve this, example using

def __eq__(self, other):     return self.next_one == other.next 

inside map class, either placed wrong or should not using problem @ all. got idea stackoverflow page on same problem:

learn python hard way, ex 49 : comparing objects using assert_equal

could please explain me how can assert output expect, , not worry whether location same?

you need able identify each instance:

class x:      def __init__(self, x):         self.x = x      def __eq__(self, other):         return self.x == other.x  

this mean constructing them need parameter:

one = x(1) other = x(1) 1 == other 

the 2 different instances equate each other due member x being equal.

in fact i've replicated accepted answer in question reference


Comments

Popular posts from this blog

networking - Vagrant-provisioned VirtualBox VM is not reachable from Ubuntu host -

c# - ASP.NET Core - There is already an object named 'AspNetRoles' in the database -

ruby on rails - ArgumentError: Missing host to link to! Please provide the :host parameter, set default_url_options[:host], or set :only_path to true -