{"id":20940378,"url":"https://github.com/fedora-python/tox-current-env","last_synced_at":"2025-04-06T12:09:23.735Z","repository":{"id":35030054,"uuid":"197379799","full_name":"fedora-python/tox-current-env","owner":"fedora-python","description":"tox plugin to run tests in current Python environment","archived":false,"fork":false,"pushed_at":"2025-03-12T15:52:01.000Z","size":121,"stargazers_count":25,"open_issues_count":19,"forks_count":9,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-03-30T11:07:19.994Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://pypi.org/project/tox-current-env/","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/fedora-python.png","metadata":{"files":{"readme":"README.rst","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-07-17T11:54:01.000Z","updated_at":"2025-03-12T15:51:52.000Z","dependencies_parsed_at":"2024-06-20T23:21:25.512Z","dependency_job_id":"c4761bcc-3bba-4071-a30c-0b8fc994cf82","html_url":"https://github.com/fedora-python/tox-current-env","commit_stats":{"total_commits":114,"total_committers":9,"mean_commits":"12.666666666666666","dds":"0.35964912280701755","last_synced_commit":"22b05190f1108ded72a9ada9ef7ecd489f388f17"},"previous_names":[],"tags_count":14,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fedora-python%2Ftox-current-env","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fedora-python%2Ftox-current-env/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fedora-python%2Ftox-current-env/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fedora-python%2Ftox-current-env/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/fedora-python","download_url":"https://codeload.github.com/fedora-python/tox-current-env/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247478323,"owners_count":20945266,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-18T23:10:10.971Z","updated_at":"2025-04-06T12:09:23.715Z","avatar_url":"https://github.com/fedora-python.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"===============\ntox-current-env\n===============\n---------------------------------------------------------------------------------------\n`tox \u003chttps://tox.readthedocs.io/\u003e`_  plugin to run tests in current Python environment\n---------------------------------------------------------------------------------------\n\nThe ``tox-current-env`` plugin adds these options:\n\n``tox --current-env``\n   Runs the tox testenv's ``commands`` in the current Python environment\n   (that is, the environment where ``tox`` is invoked from and installed in).\n   Unlike regular ``tox`` invocation, this installs no dependencies declared in ``deps``.\n   An attempt to run this with a Python version that doesn't match will fail\n   (if ``tox`` is invoked from an Python 3.7 environment, any non 3.7 testenv will fail).\n\n``tox --print-deps-to=FILE``\n    Instead of running any ``commands``, simply prints the\n    `declared dependencies \u003chttps://tox.readthedocs.io/en/latest/config.html#conf-deps\u003e`_\n    in ``deps`` to the specified ``FILE``.\n    This is useful for preparing the current environment for ``tox --current-env``.\n    Use ``-`` for ``FILE`` to print to standard output.\n\n``tox --print-extras-to=FILE``\n    Instead of running any ``commands``, simply prints the names of the\n    `declared extras \u003chttps://tox.readthedocs.io/en/latest/config.html#conf-extras\u003e`_\n    in ``extras`` to the specified ``FILE``.\n    This is useful for preparing the current environment for ``tox --current-env``.\n    Use ``-`` for ``FILE`` to print to standard output.\n\n``tox --print-dependency-groups-to=FILE``\n    Instead of running any ``commands``, simply prints the names of the\n    `declared dependency_groups \u003chttps://tox.wiki/en/latest/config.html#dependency_groups\u003e`_\n    in ``dependency_groups`` to the specified ``FILE``.\n    This is useful for preparing the current environment for ``tox --current-env``.\n    Use ``-`` for ``FILE`` to print to standard output.\n    This option only exists with tox 4 and requires at least tox 4.22.\n\n``tox --assert-config``\n    In tox 4, this option ensures that tox fails (raises an exception) if no configuration is found.\n    By default, tox 4 does not terminate when no configuration exists.\n    In tox 3, this option has no effect, but it can still be specified without causing errors.\n    This option can be used alongside other options.\n\nIt is possible to use the three printing options together, as long as the ``FILE`` is different.\n\nInvoking ``tox`` without any of the above options should behave as regular ``tox`` invocation without this plugin.\nAny deviation from this behavior is considered a bug.\n\nThe plugin disables *tox's way* of providing a testing environment,\nbut assumes that you supply one in *some other way*.\nAlways run ``tox`` with this plugin in a fresh isolated environment,\nsuch as Python virtualenv, Linux container or chroot.\n\\\nSee other caveats below.\n\n\nMotivation\n----------\n\nObviously, ``tox`` was created to run tests in isolated Python virtual environments.\nThe ``--current-env`` flag totally defeats the purpose of ``tox``.\nWhy would anybody do that, you might ask?\n\nWell, it turns out that ``tox`` became too popular and gained another purpose.\n\nThe Python ecosystem now has formal `specifications \u003chttps://packaging.python.org/specifications/\u003e`_ for many pieces of package metadata like versions or dependencies.\nHowever, there is no standardization yet for declaring *test dependencies* or *running tests*.\nThe most popular de-facto standard for that today is ``tox``,\nand we expect a future standard to evolve from ``tox.ini``.\nThis plugin lets us use ``tox``'s dependency lists and testing commands for environments other than Python venvs.\n\nWe hope this plugin will enable community best practices around ``tox`` configuration\nto grow to better accomodate non-virtualenv environments in general – for example,\nLinux distros, Conda, or containers.\n\nSpecifically, this plugin was created for `Fedora \u003chttps://fedoralovespython.org/\u003e`_'s needs.\nWhen we package Python software as RPM packages, we try to run the project's test suite during package build.\nHowever, we need to test if the software works integrated into Fedora,\nnot with packages downloaded from PyPI into a fresh environment.\nBy running the tests in *current environment*, we can achieve that.\n\nIf you are interested in the RPM packaging part of this,\nsee Fedora's `%pyproject RPM macros \u003chttps://src.fedoraproject.org/rpms/pyproject-rpm-macros\u003e`_.\n\n\nInstallation\n------------\n\nInstall this via ``pip``:\n\n.. code-block:: console\n\n   $ python -m pip install tox-current-env\n\nOr install the development version by cloning `the git repository \u003chttps://github.com/fedora-python/tox-current-env\u003e`_\nand ``pip``-installing locally:\n\n.. code-block:: console\n\n   $ git clone https://github.com/fedora-python/tox-current-env\n   $ cd tox-current-env\n   $ python -m pip install -e .\n\n\nUsage\n-----\n\nWhen the plugin is installed,\nuse ``tox`` with ``--current-env``, ``--print-deps-to``, ``--print-extras-to`` or ``--print-dependency-groups-to``\nand all the other options as usual.\nAssuming your ``tox`` is installed on Python 3.7:\n\n.. code-block:: console\n\n   $ tox -e py37 --current-env\n   py37 create: /home/pythonista/projects/holy-grail/tests/.tox/py37\n   py37 installed: ...list of packages from the current environment...\n   py37 run-test-pre: PYTHONHASHSEED='3333333333'\n   py37 run-test: commands...\n   ...runs tests in current environment's Python...\n   ___________________________________ summary ____________________________________\n     py37: commands succeeded\n     congratulations :)\n\nAttempting to run the ``py36`` environment's test will fail:\n\n.. code-block:: console\n\n   $ tox -e py36 --current-env\n   py36 create: /home/pythonista/projects/holy-grail/tests/.tox/py36\n   ERROR: InterpreterMismatch: tox_current_env: interpreter versions do not match:\n       in current env: (3, 7, 4, 'final', 0)\n       requested: (3, 6, 9, 'final', 0)\n   ___________________________________ summary ____________________________________\n   ERROR:  py36: InterpreterMismatch: tox_current_env: interpreter versions do not match:\n       in current env: (3, 7, 4, 'final', 0)\n       requested: (3, 6, 9, 'final', 0)\n\nTo get list of test dependencies, run:\n\n.. code-block:: console\n\n   $ tox -e py37 --print-deps-to -\n   py37 create: /home/pythonista/projects/holy-grail/tests/.tox/py37\n   py37 installed: ...you can see almost anything here...\n   py37 run-test-pre: PYTHONHASHSEED='3333333333'\n   dep1\n   dep2\n   ...\n   ___________________________________ summary ____________________________________\n     py37: commands succeeded\n     congratulations :)\n\nTo get a list of names of extras, run:\n\n.. code-block:: console\n\n   $ tox -e py37 --print-extras-to -\n   py37 create: /home/pythonista/projects/holy-grail/tests/.tox/py37\n   py37 installed: ...you can see almost anything here...\n   py37 run-test-pre: PYTHONHASHSEED='3333333333'\n   extra1\n   extra2\n   ...\n   ___________________________________ summary ____________________________________\n     py37: commands succeeded\n     congratulations :)\n\nTo get a list of names of dependency groups, run:\n\n.. code-block:: console\n\n   $ tox -e py37 --print-dependency-groups-to -\n   py37 create: /home/pythonista/projects/holy-grail/tests/.tox/py37\n   py37 installed: ...you can see almost anything here...\n   py37 run-test-pre: PYTHONHASHSEED='3333333333'\n   group1\n   ...\n   ___________________________________ summary ____________________________________\n     py37: commands succeeded\n     congratulations :)\n\n\nCaveats, warnings and limitations\n---------------------------------\n\ntox 4\n~~~~~\n\nThe plugin is available also for tox 4. Differences in behavior between tox 3 and 4 are these:\n\n- ``--recreate`` is no longer needed when you switch from the plugin back to standard tox.\n  Tox detects it and handles the recreation automatically.\n- The plugin does not check the requested Python version nor the environment name.\n  If you let it run for multiple environments they'll all use the same Python.\n- Deprecated ``--print-deps-only`` option is no longer available.\n- The ``--print-dependency-groups-to`` is only defined on tox 4.\n\nUse an isolated environment\n~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\nRunning (especially third party software's) tests in your system Python environment is dangerous.\nAlways use this plugin in an isolated environment,\nsuch as a Linux container, virtual machine or chroot.\nYou have been warned.\n\nDo not rely on virtualenv details\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\nIn order to support the ``python`` command in the ``commands`` section,\nthe current environment invocation of ``tox`` creates a fake virtual environment\nthat just has a symbolic link to the Python executable.\nThe link is named ``python`` even if the real interpreter's name is different\n(such as ``python3.7`` or ``pypy``).\nAny other commands are not linked anywhere and it is the users' responsibility\nto make sure such commands are in ``$PATH`` and use the correct Python.\nThis can lead to slightly different results of tests than invoking them directly,\nespecially if you have assumptions about ``sys.executable`` or other commands\nin your tests.\n\nAs a specific example, tests should invoke ``python -m pytest`` rather than assuming\nthe ``pytest`` command is present and uses the correct version of Python.\n\nDon't mix current-env and regular tox runs\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\ntox caches the virtualenvs it creates, and doesn't distinguish between\nregular virtualenvs and ``--current-env``.\nDon't mix ``tox --current-env``, ``tox --print-deps-to`` or ``tox --print-extras-to``\nruns and regular ``tox`` runs (without the flags provided by this plugin).\nIf you ever need to do this, use tox's ``--recreate/-r`` flag to clear the cache.\n\nThe plugin should abort with a meaningful error message if this is detected,\nbut in some corner cases (such as running ``tox --current-env``,\nforcefully killing it before it finished, uninstalling the plugin,\nand running ``tox``), you will get undefined results\n(such as installing packages from PyPI into your current environment).\n\nEnvironment variables are passed by default\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\nSince 0.0.9, all Shell environment variables are passed by default when using\nthis plugin. The `passenv` tox configuration is set to `*`.\nRead `the documentation for more information about passing environment variables to tox\n\u003chttps://tox.wiki/en/latest/config.html#passenv\u003e`_.\n\ntox provisioning\n~~~~~~~~~~~~~~~~\n\nThe tested projects can specify the\n`minimal tox version \u003chttps://tox.readthedocs.io/en/latest/config.html#conf-minversion\u003e`_\nand/or\n`additional requires \u003chttps://tox.readthedocs.io/en/latest/config.html#conf-requires\u003e`_\nneeded in the environment where ``tox`` is installed.\nNormally, ``tox`` uses *provisioning* when such requirements are not met.\nIt creates a virtual environment,\ninstalls (a newer version of) ``tox`` and the missing packages\ninto that environment and proxies all ``tox`` invocations trough that.\nUnfortunately, this is undesired for ``tox-current-env``.\n\n 1. It is possible to invoke ``tox`` with ``--no-provision``\n    to prevent the provision entirely.\n    When requirements are missing, ``tox`` fails instead of provisioning.\n    If a path is passed as a value for ``--no-provision``,\n    the requirements will be serialized to the file, as JSON.\n 2. The requires, if specified, are included in the\n    results of ``tox --print-deps-to``.\n    This only works when they are installed (otherwise see the first point).\n 3. The minimal tox version, if specified, is included in the results of\n    ``tox --print-deps-to``.\n    This only works when the version requirement is satisfied\n    (otherwise see the first point).\n\nThe recommend way to handle this is:\n\n 1. Run ``tox --no-provision provision.json --print-deps-to=...`` or similar.\n 2. If the command fails, install requirements from ``provision.json`` to the\n    current environment and try again.\n\nNote that the specified requirements are likely to contain\n`other tox plugins \u003chttps://tox.readthedocs.io/en/latest/plugins.html\u003e`_\nand many of them might interfere with ``tox-current-env`` in an undesired way.\nIf that is the case, the recommended way is to patch/sed such undesired plugins\nout of the configuration before running ``tox``.\n\nOther limitations and known bugs\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\nThe ``installed:`` line in the output of ``tox --print-deps-to``/``tox --print-extras-to`` shows irrelevant output\n(based on the content of the real or faked virtual environment).\n\nRegardless of any `Python flags \u003chttps://docs.python.org/3/using/cmdline.html\u003e`_ used in the shebang of ``tox``,\nthe tests are invoked with ``sys.executable`` without any added flags\n(unless explicitly invoked with them in the ``commands`` section).\n\nThe current environment's Python is tested for the major and minor version only.\nDifferent interpreters with the same Python version (such as CPython and PyPy) are treated as equal.\n\nOnly Linux is supported, with special emphasis on Fedora.\nThis plugin might work on other Unix-like systems,\nbut does not work on Microsoft Windows.\n\nThis is alpha quality software.\nUse it at your on your own risk.\nPull requests with improvements are welcome.\n\n\nDevelopment, issues, support\n----------------------------\n\nThe development happens on GitHub,\nat the `fedora-python/tox-current-env \u003chttps://github.com/fedora-python/tox-current-env\u003e`_ repository.\nYou can use the `issue tracker \u003chttps://github.com/fedora-python/tox-current-env/issues\u003e`_  there for any discussion\nor send Pull Requests.\n\n\nTests\n~~~~~\n\nIn order to run the tests, you'll need ``tox`` and Python from 3.6 to 3.10 installed.\nThe integration tests assume all of them are available.\nOn Fedora, you just need to ``dnf install tox``.\n\nRun ``tox`` to invoke the tests.\n\nRunning tests of this plugin with its own ``--current-env`` flag will most likely blow up.\n\n\nLicense\n-------\n\nThe ``tox-current-env`` project is licensed under the so-called MIT license, full text available in the `LICENSE \u003chttps://github.com/fedora-python/tox-current-env/blob/master/LICENSE\u003e`_ file.\n\n\nCode of Conduct\n---------------\n\nThe ``tox-current-env`` project follows the `Fedora's Code of Conduct \u003chttps://docs.fedoraproject.org/en-US/project/code-of-conduct/\u003e`_.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffedora-python%2Ftox-current-env","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffedora-python%2Ftox-current-env","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffedora-python%2Ftox-current-env/lists"}