【问题标题】:Python dictionary inside __init__() does not appear covered after running coverage.py in PyCharm在 PyCharm 中运行 coverage.py 后,__init__() 中的 Python 字典没有出现覆盖
【发布时间】:2016-01-13 16:58:48
【问题描述】:

如何获得下面显示的多行字典定义的所有行以指示 PyCharm 5.0.3 中的完全覆盖?

当我在 PyCharm 中运行 coverage.py 时,self.font_families_dict 中的所有行都没有被覆盖。

代码链接:fontparser.py

测试链接:test_fontParser.py

这可能是 PyCharm 5.0.3 问题、我的用户错误或 coverage.py 中的某些问题。我以前从未见过这种问题,而且我有多个初始化字典的类。

注意:

  • 左侧的绿色竖线表示该线已被覆盖。
  • 左侧红色竖线表示该行未被覆盖。

为了确保线条被搔痒,我写了这个测试:

class TestFontParser(TestCase):
    def test_font_families_dict(self):
        font_parser = FontParser()
        expected = {
            'serif': {
                'georgia', 'palatino', 'times', 'cambria', 'didot', 'garamond', 'perpetua', 'rockwell', 'baskerville',
            },
            'sans-serif': {
                'arial', 'helvetica', 'gadget', 'cursive', 'impact', 'charcoal', 'tahoma', 'geneva', 'verdana',
                'calibri', 'candara', 'futura', 'optima',
            },
            'monospace': {'courier', 'monaco', 'consolas', },
            'fantasy': {'copperplate', 'papyrus', },
        }
        self.assertEqual(font_parser.font_families_dict, expected)

【问题讨论】:

    标签: python dictionary pycharm code-coverage python-unittest


    【解决方案1】:
    • 重启 PyCharm。
    • 再次运行 Coverage。

    • 结果

    【讨论】:

      猜你喜欢
      • 2016-02-01
      • 2015-05-03
      • 2013-01-16
      • 2016-11-09
      • 1970-01-01
      • 1970-01-01
      • 2010-10-19
      • 2011-04-04
      • 2017-08-22
      相关资源
      最近更新 更多