Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MockObject should provide a way to test methods like __str__ #24

Open
ivancrneto opened this issue Jan 6, 2024 · 0 comments
Open

MockObject should provide a way to test methods like __str__ #24

ivancrneto opened this issue Jan 6, 2024 · 0 comments
Labels
enhancement New feature or request good first issue Good for newcomers

Comments

@ivancrneto
Copy link
Owner

class Foo:
    def __str__(self):
        print "Foo!"

class TestSuite(unittest.TestCase):
    def setUp(self):
        self.m = mox.Mox()
    def tearDown(self):
        self.m.UnsetStubs()

    def test_Foo_str(self):
        f = self.m.CreateMock(Foo)
        self.m.ReplayAll()
        res = str(f)  # res receives '<MockAnything instance at xx>'
        self.m.VerifyAll()

In most situations, MockObject.__str__ is useful but in some, it prevents from
testing a class's str method. Instead of receiving '<MockAnything...>' in
the example above, there should be a way to make it receive "Foo!"

@ivancrneto ivancrneto added enhancement New feature or request good first issue Good for newcomers labels Jan 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

1 participant