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
823 stars 55 forks source link

Testmon very sensitive towards library changes #183

Open dgot opened 2 years ago

dgot commented 2 years ago

Background

I have found pytest-testmon to be very sensitive towards the slightest changes for the packages in the environment it is installed. This makes very difficult to use pytest-testmon in practice when sharing a .testmondata file between our developers.

Use Case:

A developer is trying out a new library foo and have written a wrapper foo_bar.py for this. The developer only wants to run test_foo_bar.py for foo_bar.py, however the entire test suite is run since foo was installed.

Example Solution

Flag for disregarding library changes

  • I am happy to contribute with a solution, if it is considered possible.
  • If library needs funding for a solution, this is an option as well.
emavgl commented 1 year ago

Could this also be true for every changes in the requirements.txt?

tarpas commented 1 year ago

@dgot @emavgl Hello. I just pushed a beta version (install with pip install --pre pytest-testmon) which disregards changes of dependencies versions in the patch version number (after 2nd dot). Could you please try!?

tarpas commented 11 months ago

Please let me knnow if disregarding version after 2nd dot is practical enough.

emavgl commented 11 months ago

Hello! Unfortunately I don't have much time these days to try this out. Also, I am not currently using testmon at work. So, from my side, please feel free to merge the change.

jacksongoode commented 10 months ago

Sorry to be back one again with an issue, but the latest version is throwing. testmon: The packages installed in your Python environment have been changed. All tests have to be re-executed. in some cases and not skipping tests that haven't been changed in some case.

Our process is:

My guess is just that reinstalling all the dependencies on a remote environment ends up installing packages with the same version but different hashes?

tarpas commented 10 months ago

Hi Jackson, the code which retrieves current packages is here https://github.com/tarpas/pytest-testmon/blob/72c70c79aa85095df45bc201adb13bc8e7f7ec96/testmon/common.py#L36 Please create a test which uses that to get and print your environment. Then you'll see what changes. It's quite likely that your own package/packages changes with every version. You can than use the undocumented testmon_ignore_dependencies configuration option to eliminate the unwanted package. (https://github.com/tarpas/pytest-testmon/blob/72c70c79aa85095df45bc201adb13bc8e7f7ec96/testmon/pytest_testmon.py#L140C5-L140C71)

As for more intuitive and documented solutions. We'll drop the sensitivity in the future quite a bit more

jacksongoode commented 10 months ago

Ah I see, I was thinking we would also be happy to make a PR to enable/disable the hashing comparison as a flag as well.

Does one settestmon_ignore_dependencies as a flag to the pytest job or within the pytest.ini, pyproject? You might very well be right in that the wheel built for the local library will always change its hash when we pack and install it somewhere else.

jmkolbe commented 8 months ago

@jacksongoode in case you're still wondering, the setting is accepted in pytest.ini as testmon_ignore_dependencies = '<package name>'

It would not accept a list on my end. Not sure if that's by design, it would seem reasonable to want to pass a list there. Also, the message

The packages installed in your Python environment have been changed. All tests have to be re-executed

is still shown.

But it does appear to fulfill the requirement, i.e. exempting specific installed packages when evaluating if the test run needs to be repeated 👍

marcodicro-dp commented 4 months ago

I'd also like this to be less sensitive.

E.g. If I built the testmon db this morning doing a full test run, then a version change in an external library like e.g google-cloud-bigquery doesn't mean I have to run all the tests again if I made a simple code change.

I've tried adding that library to testmon_ignore_dependencies in pytest.ini without success: testmon_ignore_dependencies = 'google-cloud-bigquery'

For this to work, does testmon_ignore_dependencies have to be set when the testmon DB is built too?