【问题标题】:Preventing pytest from creating .cache directories in Pycharm防止 pytest 在 Pycharm 中创建 .cache 目录
【发布时间】:2018-05-24 10:53:15
【问题描述】:

我使用 Pycharm 来应对今年的 Advent of Code,我使用 pytest 来测试所有示例和输出。

如果 pytest 没有在我的目录树中创建 .cache 目录,我会更喜欢它。测试失败时是否可以禁用 .cache 目录的创建?

【问题讨论】:

    标签: python caching pycharm pytest


    【解决方案1】:

    有两个基本选项:

    • 完全禁用缓存(使用cacheprovider 插件完成缓存):

      pytest -p no:cacheprovider
      

      -p is used to disable plugins.

    • 通过调整cache-dir configuration option 更改缓存位置(需要pytest 3.2+)

      设置存放缓存插件内容的目录。默认目录是在 rootdir 中创建的 .cache。目录可以是相对路径或绝对路径。如果设置相对路径,则创建相对于 rootdir 的目录。

    这是一个带有no:cacheprovider 的示例 PyCharm 运行配置:

    【讨论】:

    • 谢谢,这非常有用。你知道是否有办法改变 PyCharm 的行为以使用 -p no:cacheprovider 运行它的测试?
    • @labarna 当然,您可以在 py.test 运行配置中添加其他命令行参数。如果您需要示例配置屏幕截图,请告诉我。谢谢。
    • @labarna 当然,添加了示例运行配置屏幕截图,如果有帮助请告诉我。
    猜你喜欢
    • 1970-01-01
    • 2016-06-16
    • 2017-01-04
    • 2019-10-18
    • 1970-01-01
    • 2022-01-23
    • 2022-07-05
    • 1970-01-01
    • 2015-02-13
    相关资源
    最近更新 更多