简体   繁体   English

pytest 通过 pycharm 但从命令行失败

[英]pytest passes in pycharm but fails from command line

I have a number of test classes wtih one specific one containing 12 tests.我有许多测试类,其中一个特定的包含 12 个测试。 Two of these tests pass within pycharm but not in powershell.其中两个测试在 pycharm 中通过,但在 powershell 中未通过。 One of them is this:其中之一是:

    def test_create_block_when_called_returns_correct_no_jbs(self):
        designer = BlockDesigner(CsvStore(self.config), FakeRouter(), self.config)
        block = designer.create_block("BK1")

        result = len(block.junction_boxes)

        assert result == 10

It passes perfectly from within pycharm.它从 pycharm 内完美通过。 When run outside, it fails on the assert criteria:在外面运行时,它在断言标准上失败:

>       assert result == 10
E       assert 9 == 10

This would suggest it gets a different setup from the command line than when run inside pycharm.这表明它从命令行获得的设置与在 pycharm 中运行时不同。 This test class has a setup_method that instantiates the required config files and am specifically careful to get the current paths since these tests also run in DevOps:这个测试 class 有一个setup_method实例化所需的配置文件,并特别注意获取当前路径,因为这些测试也在 DevOps 中运行:

    def setup_method(self):
        self.path = str(pathlib.Path(__file__).parent.absolute())
        self.config = Configuration(self.path + "/test_config.yml").get_config()

I have a similar problem with one other test in this test class but all other 10 using the same setup, passes on the command line.我在这个测试 class 中的另一个测试有类似的问题,但所有其他 10 个使用相同的设置,通过命令行。

First time I have ever encountered this.我第一次遇到这种情况。 Is there something I am missing in the setup_method perhaps? setup_method中是否有我遗漏的东西?

OK, so it was indeed a config setup issue.好的,所以这确实是一个配置设置问题。 These errors are annoying and was completely mine.这些错误很烦人,完全是我的。 There was an additional config file path that I had to pre-fix with str(pathlib.Path(__file__).parent.absolute()) .我必须使用str(pathlib.Path(__file__).parent.absolute())预先修复一个额外的配置文件路径。 An oversight.一个疏忽。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM