Skip to content

Cassette recording failure for tests which extend setUpClass #186

Open
@FriedrichFroebel

Description

@FriedrichFroebel

Recording a new cassette for the following test fails inside tests.test_trackable.TestMethods (for #185):

    def test_load__type(self):
        with self.subTest("existing"):
            trackable = Trackable(self.gc, "TB1KEZ9")
            with self.recorder.use_cassette("trackable_load__existing_type"):
                self.assertEqual("SwedenHawk Geocoin", trackable.type)

        with self.subTest("missing"):
            trackable = Trackable(self.gc, "TB7WZD9")
            with self.recorder.use_cassette("trackable_load__missing_type"):
                self.assertEqual(None, trackable.type)

The errors are (running pytest -k "test_load__type" --log-level DEBUG for example):

=============================================================================== FAILURES ================================================================================
______________________________________________________________________ TestMethods.test_load__type ______________________________________________________________________

args = (<pycaching.trackable.Trackable object at 0x7f71f85f8cd0>,), kwargs = {}, self = <pycaching.trackable.Trackable object at 0x7f71f85f8cd0>

    @functools.wraps(func)
    def wrapper(*args, **kwargs):
        self = args[0]
        try:
>           return func(*args, **kwargs)

pycaching/util.py:30: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

self = <pycaching.trackable.Trackable object at 0x7f71f85f8cd0>

    @property
    @lazy_loaded
    def type(self):
        """The trackable type.
    
        A type depends on the trackable icon. It can be either "Travel Bug Dog Tag" or specific
            geocoin name, eg. "Adventure Race Hracholusky 2015 Geocoin".
    
        :type: :class:`str`
        """
>       return self._type
E       AttributeError: 'Trackable' object has no attribute '_type'

pycaching/trackable.py:152: AttributeError

During handling of the above exception, another exception occurred:

self = <test.test_trackable.TestMethods testMethod=test_load__type>

    def test_load__type(self):
        with self.subTest("existing"):
            trackable = Trackable(self.gc, "TB1KEZ9")
            with self.recorder.use_cassette("trackable_load__existing_type"):
>               self.assertEqual("SwedenHawk Geocoin", trackable.type)

test/test_trackable.py:92: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
pycaching/util.py:33: in wrapper
    self.load()
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

self = <pycaching.trackable.Trackable object at 0x7f71f85f8cd0>

    def load(self):
        """Load all possible details about the trackable.
    
        .. note::
           This method is called automatically when you access a property which isn't yet filled in
           (so-called "lazy loading"). You don't have to call it explicitly.
    
        :raise .LoadError: If trackable loading fails (probably because of not existing trackable).
        """
        # pick url based on what info we have right now
        if hasattr(self, "url"):
            url = self.url
        elif hasattr(self, "_tid"):
            url = "track/details.aspx?tracker={}".format(self._tid)
        else:
            raise errors.LoadError("Trackable lacks info for loading")
    
        # make request
        root = self.geocaching._request(url)
    
        # parse data
        self.tid = root.find("span", "CoordInfoCode").text
        self.name = root.find(id="ctl00_ContentBody_lbHeading").text
        self.type = root.find(id="ctl00_ContentBody_BugTypeImage").get("alt")
        self.owner = root.find(id="ctl00_ContentBody_BugDetails_BugOwner").text
        self.goal = root.find(id="TrackableGoal").text
        self.description = root.find(id="TrackableDetails").text
>       self._kml_url = root.find(id="ctl00_ContentBody_lnkGoogleKML").get("href")
E       AttributeError: 'NoneType' object has no attribute 'get'

pycaching/trackable.py:196: AttributeError

Debugging this yields the result that the login is successful, but the trackable page is rendered as logged-out user, thus not containing the KML data.

Disabling the setup cassette loader in this class seems to fix this issue, although it is now clear to me why:

    @classmethod
    def setUpClass(cls):
        super().setUpClass()
        cls.t = Trackable(cls.gc, "TB1KEZ9")
        # with cls.recorder.use_cassette("trackable_setup"):
        #     cls.t.load()

We should do some more investigation on what actually causes this issue/side effect and fix it.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions