Terry J. Reedy <tjre...@udel.edu> added the comment:

Without lines numbers, I cannot test which of the two identical asserts failed. 
Either comments or msg arguments will differentiate.  Nor can I run snippets 
from two different files. Here is a minimal reproducible self-contained code 
that demonstrates the claim (which I verified on 3.9 and current master).

import unittest
from unittest.mock import Mock

class SomethingElse(object):
    def __init__(self):
        self._instance = None

    @property
    def instance(self):
        if not self._instance:
            self._instance = 'object'

class Test(unittest.TestCase):

    def test_property_not_called_with_spec_mock(self):
        obj = SomethingElse()
        self.assertIsNone(obj._instance, msg='before') # before
        mock = Mock(spec=obj)
        self.assertIsNone(obj._instance, msg='after') # after

unittest.main()

----------
nosy: +michael.foord, terry.reedy
versions: +Python 3.10, Python 3.9

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue41768>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to