pytest passes in pycharm but fails from command line

Viewed 681

I have a number of test classes wtih one specific one containing 12 tests. Two of these tests pass within pycharm but not in 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. 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. 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:

    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.

First time I have ever encountered this. Is there something I am missing in the setup_method perhaps?

1 Answers

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()). An oversight.

Related