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

PIP runner introduction #6072

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

richtja
Copy link
Contributor

@richtja richtja commented Nov 26, 2024

This PR introduces a new dependency runner called pip. With this runner, avocado will be able to manipulate with python packages in test environment based on the test dependency configuration. The runner will install pip into the test environment, and then it can call pip install or pip uninstall commands. For example, this feature can be used for running coverage.py inside different environments than process.

Copy link

codecov bot commented Nov 26, 2024

Codecov Report

Attention: Patch coverage is 80.00000% with 9 lines in your changes missing coverage. Please review.

Project coverage is 68.70%. Comparing base (cee5223) to head (8266190).
Report is 3 commits behind head on master.

Files with missing lines Patch % Lines
avocado/plugins/runners/pip.py 80.00% 9 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #6072      +/-   ##
==========================================
+ Coverage   68.67%   68.70%   +0.02%     
==========================================
  Files         202      203       +1     
  Lines       21892    21937      +45     
==========================================
+ Hits        15034    15071      +37     
- Misses       6858     6866       +8     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

This commit introduces a new dependency runner called `pip`. With this
runner, avocado will be able to manipulate with python packages in test
environment based on the test dependency configuration. The runner will
install pip into the test environment, and then it can call `pip
install` or `pip uninstall` commands. For example, this feature can be
used for running `coverage.py` inside different environments than
process.

Signed-off-by: Jan Richter <[email protected]>
Copy link
Contributor

@clebergnu clebergnu left a comment

Choose a reason for hiding this comment

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

Hi @richtja ,

This is a great idea, and a have a few comments for immediate changes, and somethings that can/should follow up later.

As for immediate changes, I mentioed the req-pac bits in the selftests.

Also, please add this variant to the nrunner-interface suite in selftests/check.py. While at it, add a selftests/functional/nrunner_interface.py.data/recipe_runnable_pip.json file (which can be a link or copy of the existing example file in this PR), but consider its actual execution and network access, etc.

It'd also be nice to add a test with a dependency as an example. I found that it's possible to do something like examples/tests/dependency_pip.py:

from avocado import Test, fail_on


class Pip(Test):
    """
    :avocado: dependency={"type": "pip", "name": "pip", "action": "install"}
    """

    @fail_on(ImportError)
    def test(self):
        import pip

It may seem pointless, but it's something that can run pretty much in every Python environment without causing disruption (installing extra modules).

As future points:

  1. This looks like it could be part of a replacement for the use of eggs for Avocado's own automatic deployment
  2. It would be nice to support the location destination where the pip modules will be installed (such as a venv). This would be especially useful for Avocado's own automatic deployment.
  3. Support for multiple pip packages instead of one at a time

class TaskRun(unittest.TestCase):
def test_no_kwargs(self):
res = process.run(
f"{RUNNER} task-run -i XXXreq-pacXXX -k pip", ignore_status=True
Copy link
Contributor

Choose a reason for hiding this comment

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

The req-pac bits are understandably copies from the similar existing test you used as the basis for this, but may cause confusion on people reading this code. I suggest you change it to something easier to understand.

self.assertIn(b"'time': ", res.stdout)
self.assertEqual(res.exit_status, 0)

@unittest.skipUnless(
Copy link
Contributor

Choose a reason for hiding this comment

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

An idea: I think we're at a point where we need to stop depending on the CI environment flag, and determine whether the environment the test is running:

  • can be written permanently and destructively
  • has network access

Of course we can look into CI environment variables and the like, but it would make the SKIPs much more manageable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Review Requested
Development

Successfully merging this pull request may close these issues.

2 participants