tarpas / pytest-testmon

Selects tests affected by changed files. Executes the right tests first. Continuous test runner when used with pytest-watch.
https://testmon.org
MIT License
800 stars 54 forks source link

Ability to run testmon on an installed package #208

Closed adkinsjd closed 1 year ago

adkinsjd commented 1 year ago

We (@jacksongoode and I) are trying to use testmon in a managed environment (Databricks jobs) that requires all code be contained either within a single python script or be installed as a package. To do so we package the code we want to test, install it, then upload and run a script that invokes pytest with testmon and sets the pytest rootdir to the site-packages directory of package we are testing.

In this setup the correct tests are collected and run, but testmon doesn't detect changes in the package code, only the tests themselves. Is there a way to configure pytest/testmon/the environment such that testmon can detect changes to the code of a specific installed package.

More broadly, how does testmon choose which directories to analyze with coverage? Is there some way, either in current testmon, or as a new feature, to add a directory to what testmon considers the "source" code?

We've tried a number of pytest configurations including changing the rootdir and testpaths for pytest. We have considered, but have not tried manually manipulating the environment in our testing script, perhaps modifying the python path. It's hard to know what to do without a deeper understanding of how testmon selects which directories to check for changes and how testmon excludes installed packages from those checks.

tarpas commented 1 year ago

testmon includes pytest rootdir in it's coverage and excludes sys.prefix . Including everything is prohibitive performance wise and I don't have a clear idea how to support multiple directories.

Also we're working on a feature of sharing testmondata across systems and I don't have a clear idea how to support python paths which are portable across systems.

coverage deals with this problems in it's way but the merging of files is clumsy and slow, so not usable for acceleration tool like testmon.

For the coming months the answer, I'm afraid, is that testmon only supports editable installs where everything you need to track is under pytest rootdir.

adkinsjd commented 1 year ago

In this case everything we are tracking is in the pytest rootdir because the rootdir is set to the site-packages directory for the package - it is just also installed as a package.

Does the exclusion of sys.prefix override the inclusion of everything in the rootdir?

adkinsjd commented 1 year ago

Is there a way to list all files being included in the coverage analysis?

adkinsjd commented 1 year ago

I think we figured this out by setting both the testpath and rootdir to the site-packages directory of the installed package.

There still seems to be some odd behavior when doing this, but I'm having trouble isolating and reproducing it. I'll report back with a new issue if I find a more specific bug.