Changeset 1756:ad291ad87245


Ignore:
Timestamp:
Jan 28, 2019, 7:43:11 PM (3 years ago)
Author:
Stefan Schwarzer <sschwarzer@…>
Branch:
default
Message:
Prefix `print`s with `ScriptedSession` instance

When printing from a `ScriptedSession` instance for
tracking/debugging, prepend information on the respective
`ScriptedSession` instance.

Example:

  <ScriptedSession at 0x7ff1881a72e8> Expected method name: '__init__'

This makes it much clearer what's going on if a test needs more than
one `ScriptedSession`.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • test/scripted_session.py

    r1755 r1756  
    8282        init()
    8383
     84    def _print(self, text):
     85        """
     86        Print `text`, prefixed with a `repr` of the `ScriptedSession`
     87        instance.
     88        """
     89        print("<ScriptedSession at {}> {}".format(hex(id(self)), text))
     90
    8491    def _next_call(self, expected_method_name=None):
    8592        """
     
    8996        testing and debugging.
    9097        """
    91         print("Expected method name: {!r}".format(expected_method_name))
     98        self._print("Expected method name: {!r}".format(expected_method_name))
    9299        call = self.script[self._index]
    93100        self._index += 1
    94         print("Next call: {!r}".format(call))
     101        self._print("Next call: {!r}".format(call))
    95102        if expected_method_name is not None:
    96103            assert call.method_name == expected_method_name, (
     
    102109        call = self._next_call(expected_method_name=attribute_name)
    103110        def dummy_method(*args, **kwargs):
    104             print("args: {!r}".format(args))
    105             print("kwargs: {!r}".format(kwargs))
     111            self._print("args: {!r}".format(args))
     112            self._print("kwargs: {!r}".format(kwargs))
    106113            call.check_args(args, kwargs)
    107114            return call()
Note: See TracChangeset for help on using the changeset viewer.