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

tox 4: enable plugins to run before/after each testenv #2201

Closed
dcrosta opened this issue Sep 3, 2021 · 1 comment
Closed

tox 4: enable plugins to run before/after each testenv #2201

dcrosta opened this issue Sep 3, 2021 · 1 comment
Labels
area:plugins-hooks feature:new something does not exist yet, but should
Milestone

Comments

@dcrosta
Copy link
Member

dcrosta commented Sep 3, 2021

My plugin tox-docker needs a way to run code before and after the testing part of each testenv.

Before each testenv runs, tox-docker will start appropriate docker containers based on configuration (see #2200 for more), and sets environment variables for the testenv to inform tests of the containers' IP and ports. After the test run, the containers are stopped and removed.

This could either mean bringing back tox_runtest_pre and tox_runtest_post, or adding tox_wrap_test which could act like a generator-context manager. For example:

@impl
@contextmanager
def tox_wrap_test(env: TestEnv):
    # ... start docker containers ...

    try:
        yield  # tests run here
    finally:
        # ... clean up started containers ...
@dcrosta dcrosta added the feature:new something does not exist yet, but should label Sep 3, 2021
@gaborbernat gaborbernat added this to the 4.0 milestone Sep 5, 2021
@ymyzk
Copy link

ymyzk commented Sep 10, 2021

tox-gh-actions also has a similar request. It has been using tox_runtest_pre and tox_runtest_post hooks to use log line grouping on GitHub Actions and we'd like to implement something similar for tox v4 as well. ymyzk/tox-gh-actions#39 ymyzk/tox-gh-actions#80

Here's what we want to do:

$ tox4
.pkg: get_requires_for_build_sdist> python ... True setuptools.build_meta __legacy__
.pkg: prepare_metadata_for_build_wheel> python ... True setuptools.build_meta __legacy__
.pkg: build_sdist> python ... True setuptools.build_meta __legacy__

(tox-gh-actions wants to write the start of the log line grouping here)

flake8: install_package> python -I -m pip install --force-reinstall --no-deps ...
flake8: commands[0]> flake8 setup.py

(tox-gh-actions wants to write the end of the log line grouping here)

.pkg: _exit> python ... True setuptools.build_meta __legacy__
  flake8: OK (1.53=setup[1.34]+cmd[0.18] seconds)
  congratulations :) (1.57 seconds)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:plugins-hooks feature:new something does not exist yet, but should
Projects
None yet
Development

No branches or pull requests

3 participants