serhii.net

In the middle of the desert you can say anything you want

11 Jan 2022

poetry pytest takes too long to collect + tell it to ignore certain directories

pytest took seconds at the “Collecting…” stage.

I had a directory with a lot of tiny files (./data_1234/) in the poetry package folder, and blamed it initially.

SO1 told me that the syntax to ignore a folder is

[tool:pytest]
norecursedirs = subpath/*

Wildcards are nice and data*/* was the first attempt.

Nothing.

Then I without success tried this:

testpaths="tests"

After a one-hour saga, I found that the culprit was a package that I was using. The tests imported my package, which imported the slow package, and it takes seconds to do so.

‘Collecting’ seems not to be only “find test files”, but it reads them and imports them and all their dependencies.

Waiting time went back to normal as soon as I commented out importing my package from the test.

Nel mezzo del deserto posso dire tutto quello che voglio.