This is literally the whole unittest.<br><br><br>    import unittest<br>    from mock import patch<br>    from yaml import safe_load<br>    <br>    from graphyte.tests.do_config import read_config<br>    from graphyte.graphapp.model.codebundle import CodeBundle<br>
    <br>    test_config = read_config()<br>    This is literally the whole unittest.<br><br><br>    import unittest<br>    from mock import patch<br>    from yaml import safe_load<br>    <br>    from graphyte.tests.do_config import read_config<br>
    from graphyte.graphapp.model.codebundle import CodeBundle<br>    <br>    test_config = read_config()<br>    <br>    class TestCodebundleBBDSModel(unittest.TestCase):<br>        def setUp(self):<br>            self.patcher1 = patch(&#39;graphyte.graphapp.model.codebundle.CodeBundle&#39;, autospec=True)<br>
            self.cb = self.patcher1.start()<br>    <br>        def tearDown(self):<br>            self.patcher1.stop()<br>    <br>        def test_bbds_list(self):<br>            self.cb.return_value.tempdir = test_config[&#39;unit-fixtures&#39;]<br>
            bbds_list = self.cb.return_value.bbds_list.return_value<br>            expected = [&#39;123&#39;, &#39;456&#39;]<br>    <br>            self.assertEqual(expected, bbds_list)<br><br>instead I get <br><br>      File &quot;test_codebundles.py&quot;, line 26, in test_bbds_list<br>
        self.assertEqual(expected, bbds_list)<br>    AssertionError: [&#39;123&#39;, &#39;456&#39;] != &lt;MagicMock name=&#39;CodeBundle().bbds_list()&#39; id=&#39;173575436&#39;&gt;<br><br><br>I tried with and without `return_value` and with and without `()`, but it yields nothing useful.<br>
<br>Here is the system under test<br><br>    def bbds_list(self):<br>        assert self.setup_tempdir()<br>        datalist_path = os.path.join(self.tempdir, &#39;.datalist.yaml&#39;)<br>        with open(datalist_path, &#39;r&#39;) as f:<br>
            configs = safe_load(f)<br>            bbids = configs[&#39;bbids&#39;]<br>            return list(bbids.iterkeys())<br><br>Another problem I encouter is I cannot make the attribute `self.tempdir` on the fly.<br>
<br>Any idea what&#39;s wrong with my test code?<br><br>    class TestCodebundleBBDSModel(unittest.TestCase):<br>        def setUp(self):<br>            self.patcher1 = patch(&#39;graphyte.graphapp.model.codebundle.CodeBundle&#39;, autospec=True)<br>
            self.cb = self.patcher1.start()<br>    <br>        def tearDown(self):<br>            self.patcher1.stop()<br>    <br>        def test_bbds_list(self):<br>            self.cb.return_value.tempdir = test_config[&#39;unit-fixtures&#39;]<br>
            bbds_list = self.cb.return_value.bbds_list.return_value<br>            expected = [&#39;123&#39;, &#39;456&#39;]<br>    <br>            self.assertEqual(expected, bbds_list)<br><br>instead I get <br><br>      File &quot;test_codebundles.py&quot;, line 26, in test_bbds_list<br>
        self.assertEqual(expected, bbds_list)<br>    AssertionError: [&#39;123&#39;, &#39;456&#39;] != &lt;MagicMock name=&#39;CodeBundle().bbds_list()&#39; id=&#39;173575436&#39;&gt;<br><br><br>I tried with and without `return_value` and with and without `()`, but it yields nothing useful.<br>
<br>Here is the system under test<br><br>    def bbds_list(self):<br>        assert self.setup_tempdir()<br>        datalist_path = os.path.join(self.tempdir, &#39;.datalist.yaml&#39;)<br>        with open(datalist_path, &#39;r&#39;) as f:<br>
            configs = safe_load(f)<br>            bbids = configs[&#39;bbids&#39;]<br>            return list(bbids.iterkeys())<br><br>Another problem I encounter is I cannot make the attribute `self.tempdir` on the fly. I want to asself self.cb the object an attribute called `self.tempdir`.<br>
<br>Any idea what&#39;s wrong with my test code? I am confused why we always need to use `return_value`. <br><br>