Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test the resolver with the install_deps option #297

Merged
merged 7 commits into from
May 9, 2023

Conversation

Nour-Mws
Copy link
Collaborator

@Nour-Mws Nour-Mws commented Apr 6, 2023

⚠️ Do not merge until the following has landed:

I opted to make this into a separate PR from the refactor PR because the battery of hypothesis tests slows down significantly with this change (it now takes ~35 seconds to run tests in test_resolver.py).

The second commit is my attempt to speed things up by installing packages from wheels instead of tarballs. Although the package is installed from the wheel (see log below), the gain in speed is not significant.

Looking in links: /home/nour/.cache/pytest/d/fawltydeps
Processing /home/nour/.cache/pytest/d/fawltydeps/leftpadx-0.0.1-py3-none-any.whl
Installing collected packages: leftpadx
Successfully installed leftpadx-0.0.1

I've also tried to skip the get_tarballs() step (which logically should not involve any time-consuming logic if the tarballs are already downloaded). Unfortunately, I did not see any speed improvement.

@Nour-Mws Nour-Mws requested review from jherland and mknorps April 6, 2023 21:26
@Nour-Mws Nour-Mws added this to the Mapping strategy milestone Apr 6, 2023
@Nour-Mws Nour-Mws force-pushed the nour/refactor-resover-tests branch 5 times, most recently from e7443ab to 3725cef Compare April 20, 2023 17:27
Base automatically changed from nour/refactor-resover-tests to main April 24, 2023 07:06
@Nour-Mws Nour-Mws force-pushed the nour/test_resolver_with_install_deps branch from c0fc39d to 9160cdd Compare April 24, 2023 12:07
@Nour-Mws
Copy link
Collaborator Author

@jherland, Having merged #296, I rebased this PR on main and it's now ready for review.

@Nour-Mws Nour-Mws force-pushed the nour/test_resolver_with_install_deps branch from 9160cdd to 9a9eb71 Compare April 24, 2023 12:15
@Nour-Mws Nour-Mws force-pushed the nour/test_resolver_with_install_deps branch from d918986 to dc402f6 Compare April 25, 2023 20:40
@Nour-Mws
Copy link
Collaborator Author

Nour-Mws commented Apr 25, 2023

@jherland dc402f6 implements the solution we agreed upon this morning.
On my local machine, this test now takes around 6 seconds to complete.

Copy link
Member

@jherland jherland left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I love the idea of using the pytest cache to cache this venv across test runs, but I really don't like having to import pytest in our shipped FawltyDeps code in order to make it work. I think it should be possible to move all the pytest-specific stuff into the test_resolver, and only leave a path to the prepared venv here.

See below for individual suggestions, or look at jherland@841ab91 for a commit on top of this that contains all my suggestions.

@Nour-Mws Nour-Mws force-pushed the nour/test_resolver_with_install_deps branch from dc402f6 to 8e71b4b Compare May 9, 2023 09:55
@Nour-Mws Nour-Mws requested a review from jherland May 9, 2023 12:36
@Nour-Mws
Copy link
Collaborator Author

Nour-Mws commented May 9, 2023

@jherland this is ready for a final look! Thanks a lot for the helpful suggestions and detailed comments.

Copy link
Member

@jherland jherland left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚀 🚀 🚀

Nour-Mws and others added 7 commits May 9, 2023 16:01
This option is not available via the `resolve_dependencies` function
which calls `TemporaryPipInstallResolver`.
In tests, patch `TemporaryPipInstallResolver` so that it's called with
the cache option.
The last changes defined the cache in TemporaryPipInstallResolver with
Pytest's cache. We introduce a new class member `cached_venv`, to
TemporaryPipInstallResolver. This is only used by `test_resolver()`
where it's set to a Pytest's cache directory, thus removing the direct
dependency of TemporaryPipInstallResolver on Pytest.

Furthermore, the new TemporaryPipInstallResolver context manager
introduced in the recent changes reuses code for intsalling requirements
and managing the venv from `temp_installed_requirements()`.
This commit splits out this duplicate code into a context manager,
`installed_requirements()`, that manages the venv creation (if needed)
and installs packages.
The existing `temp_installed_requirements()` context manager will then
only concern itself with creating the temporary directory (and delegate
to installed_requirements() for the rest).

As this replaces the initialization logic in TemporaryPipInstallResolver
with a simple class member that defines the cached_venv, it allows us to
avoid depending on pytest-mock for patching the class.

Co-authored-by: Johan Herland <[email protected]>
@Nour-Mws Nour-Mws force-pushed the nour/test_resolver_with_install_deps branch from 9f2fd34 to 6ba3523 Compare May 9, 2023 14:04
@Nour-Mws Nour-Mws merged commit 36d37a0 into main May 9, 2023
@Nour-Mws Nour-Mws deleted the nour/test_resolver_with_install_deps branch May 9, 2023 17:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants