How to use envbindir method in tox

Best Python code snippet using tox_python

test_tox_console_scripts_int.py

Source:test_tox_console_scripts_int.py Github

copy

Full Screen

1from pathlib import Path2import pytest3def assert_console_script_installed_once(script_name, path, outlines):4 expected = f"Generating script {script_name} into {path}"5 matches = [l for l in outlines if l == expected]6 assert len(matches) == 1, outlines7def assert_shebang(script, expected_shebang):8 with open(script, encoding="utf-8") as f:9 actual_shebang = f.readline()10 assert actual_shebang == expected_shebang11@pytest.fixture(autouse=True)12def isolated_env(monkeypatch):13 monkeypatch.setenv("PIP_NO_BUILD_ISOLATION", "NO")14 monkeypatch.setenv("PIP_NO_INDEX", "YES")15 monkeypatch.setenv("PIP_DISABLE_PIP_VERSION_CHECK", "1")16 monkeypatch.setenv(17 "TOX_TESTENV_PASSENV",18 "PIP_NO_BUILD_ISOLATION PIP_NO_INDEX PIP_DISABLE_PIP_VERSION_CHECK",19 )20def test_no_plugin_usage(tox_project, tox):21 """Plugin doesn't break regular tox"""22 project = tox_project()23 project.contents[24 "tox.ini"25 ] = """\26 [tox]27 skipsdist = True28 [testenv]29 commands=python -c "print('Hello, hello')"30 """31 project.make()32 result = tox("-vv", cwd=project.location)33 assert result.returncode == 034 assert b"Hello, hello" in result.stdout35 assert result.stderr == b""36def test_cmd_sitepackages_cmd(tox_project, tox):37 project = tox_project()38 project.contents[39 "tox.ini"40 ] = """\41 [tox]42 skipsdist = True43 [testenv]44 commands=python -c "print('Hello, hello')"45 """46 project.make()47 result = tox("--console-scripts", "--sitepackages", cwd=project.location)48 assert result.returncode == 049 assert b"Hello, hello" in result.stdout50 assert result.stderr == b""51def test_cmd_sitepackages_config(tox_project, tox):52 project = tox_project()53 project.contents[54 "tox.ini"55 ] = """\56 [tox]57 skipsdist = True58 [testenv]59 sitepackages = True60 commands=python -c "print('Hello, hello')"61 """62 project.make()63 result = tox("--console-scripts", cwd=project.location)64 assert result.returncode == 065 assert b"Hello, hello" in result.stdout66 assert result.stderr == b""67def test_cmd_nositepackages(tox_project, tox):68 project = tox_project()69 project.contents[70 "tox.ini"71 ] = """\72 [tox]73 skipsdist = True74 [testenv]75 commands=python -c "print('Hello, hello')"76 """77 project.make()78 result = tox("--console-scripts", cwd=project.location)79 assert result.returncode != 080 assert b"console_scripts option requires enabled sitepackages" in result.stderr81def test_config_sitepackages_cmd(tox_project, tox):82 project = tox_project()83 project.contents[84 "tox.ini"85 ] = """\86 [tox]87 skipsdist = True88 [testenv]89 console_scripts = True90 commands=python -c "print('Hello, hello')"91 """92 project.make()93 result = tox("--sitepackages", cwd=project.location)94 assert result.returncode == 095 assert b"Hello, hello" in result.stdout96 assert result.stderr == b""97def test_config_sitepackages_config(tox_project, tox):98 project = tox_project()99 project.contents[100 "tox.ini"101 ] = """\102 [tox]103 skipsdist = True104 [testenv]105 console_scripts = True106 sitepackages = True107 commands=python -c "print('Hello, hello')"108 """109 project.make()110 result = tox(cwd=project.location)111 assert result.returncode == 0112 assert b"Hello, hello" in result.stdout113 assert result.stderr == b""114def test_config_nositepackages(tox_project, tox):115 project = tox_project()116 project.contents[117 "tox.ini"118 ] = """\119 [tox]120 skipsdist = True121 [testenv]122 console_scripts = True123 commands=python -c "print('Hello, hello')"124 """125 project.make()126 result = tox(cwd=project.location)127 assert result.returncode != 0128 assert b"console_scripts option requires enabled sitepackages" in result.stderr129def test_deps_skipsdist(system_distribution, tox_project, tox):130 distr = system_distribution()131 distr.make()132 project = tox_project()133 project.contents[134 "tox.ini"135 ] = """\136 [tox]137 skipsdist = True138 [testenv]139 deps =140 foo>=1.0141 commands={envbindir}/foo_script142 """143 project.make()144 result = tox("--console-scripts", "--sitepackages", "-vv", cwd=project.location)145 assert result.returncode == 0146 assert result.stderr == b""147 stdout_lines = result.stdout.decode("utf-8").splitlines()148 # result of main function149 assert "Hello, World!" in stdout_lines150 envbindir = (Path(".tox") / "python" / "bin").resolve()151 assert_console_script_installed_once(152 "foo_script", path=envbindir, outlines=stdout_lines153 )154 expected_shebang = f"#!{envbindir / 'python'}\n"155 assert_shebang(envbindir / "foo_script", expected_shebang)156def test_no_deps_skipsdist(system_distribution, tox_project, tox):157 distr = system_distribution()158 distr.make()159 project = tox_project()160 project.contents[161 "tox.ini"162 ] = """\163 [tox]164 skipsdist = True165 [testenv]166 commands={envbindir}/foo_script167 """168 project.make()169 result = tox("--console-scripts", "--sitepackages", "-vv", cwd=project.location)170 assert result.returncode == 0171 assert result.stderr == b""172 stdout_lines = result.stdout.decode("utf-8").splitlines()173 # result of main function174 assert "Hello, World!" in stdout_lines175 envbindir = (Path(".tox") / "python" / "bin").resolve()176 assert_console_script_installed_once(177 "foo_script", path=envbindir, outlines=stdout_lines178 )179 expected_shebang = f"#!{envbindir / 'python'}\n"180 assert_shebang(envbindir / "foo_script", expected_shebang)181def test_install_requires(system_distribution, tox_project, tox):182 distr = system_distribution()183 distr.make()184 project = tox_project()185 project.contents[186 "setup.cfg"187 ] = """\188 [metadata]189 name = my_test_pkg190 description = my_test_pkg project191 version = 1.0192 license = MIT193 platforms = unix194 [options]195 packages = find:196 install_requires =197 foo198 [options.packages.find]199 where = .200 """201 project.contents[202 "tox.ini"203 ] = """\204 [tox]205 [testenv]206 commands={envbindir}/foo_script207 """208 project.make()209 result = tox("--console-scripts", "--sitepackages", "-vv", cwd=project.location)210 assert result.returncode == 0211 assert result.stderr == b""212 stdout_lines = result.stdout.decode("utf-8").splitlines()213 # result of main function214 assert "Hello, World!" in stdout_lines215 envbindir = (Path(".tox") / "python" / "bin").resolve()216 assert_console_script_installed_once(217 "foo_script", path=envbindir, outlines=stdout_lines218 )219 expected_shebang = f"#!{envbindir / 'python'}\n"220 assert_shebang(envbindir / "foo_script", expected_shebang)221def test_install_requires_usedevelop(system_distribution, tox_project, tox):222 distr = system_distribution()223 distr.make()224 project = tox_project()225 project.contents[226 "setup.cfg"227 ] = """\228 [metadata]229 name = my_test_pkg230 description = my_test_pkg project231 version = 1.0.0232 license = MIT233 platforms = unix234 [options]235 packages = find:236 install_requires =237 foo238 [options.packages.find]239 where = .240 """241 project.contents[242 "tox.ini"243 ] = """\244 [tox]245 [testenv]246 usedevelop=true247 commands={envbindir}/foo_script248 """249 project.make()250 result = tox("--console-scripts", "--sitepackages", "-vv", cwd=project.location)251 assert result.returncode == 0252 assert result.stderr == b""253 stdout_lines = result.stdout.decode("utf-8").splitlines()254 # result of main function255 assert "Hello, World!" in stdout_lines256 envbindir = (Path(".tox") / "python" / "bin").resolve()257 assert_console_script_installed_once(258 "foo_script", path=envbindir, outlines=stdout_lines259 )260 expected_shebang = f"#!{envbindir / 'python'}\n"261 assert_shebang(envbindir / "foo_script", expected_shebang)262def test_extra_usedevelop(system_distribution, tox_project, tox):263 distr = system_distribution()264 distr.make()265 project = tox_project()266 project.contents[267 "setup.cfg"268 ] = """\269 [metadata]270 name = my_test_pkg271 description = my_test_pkg project272 version = 1.0273 license = MIT274 platforms = unix275 [options]276 packages = find:277 [options.packages.find]278 where = .279 [options.extras_require]280 tests =281 foo282 """283 project.contents[284 "tox.ini"285 ] = """\286 [tox]287 [testenv]288 extras =289 tests290 usedevelop=true291 commands={envbindir}/foo_script292 """293 project.make()294 result = tox("--console-scripts", "--sitepackages", "-vv", cwd=project.location)295 assert result.returncode == 0296 assert result.stderr == b""297 stdout_lines = result.stdout.decode("utf-8").splitlines()298 # result of main function299 assert "Hello, World!" in stdout_lines300 envbindir = (Path(".tox") / "python" / "bin").resolve()301 assert_console_script_installed_once(302 "foo_script", path=envbindir, outlines=stdout_lines303 )304 expected_shebang = f"#!{envbindir / 'python'}\n"...

Full Screen

Full Screen

__init__.py

Source:__init__.py Github

copy

Full Screen

1# Copyright (c) 2018, Ioannis Tziakos2# All rights reserved.3#4# Plugin hooks are inspired by the current implementations found in5# the tox.venv module and adapted to support edm.6import subprocess7import os8import re9import sys10from tox import hookimpl, exception11from tox.venv import VirtualEnv12COMMAND_FAILED = (13 "command failed but result from testenv is ignored\ncmd: {}")14def env_exists(edm, envname):15 try:16 subprocess.check_call([str(edm), 'envs', 'exists', envname])17 except subprocess.CalledProcessError:18 return False19 else:20 return True21@hookimpl22def tox_testenv_create(venv, action):23 name = venv.envconfig.basepython24 m = re.match(r"python(\d)\.(\d)", name)25 if m:26 version = "%s.%s" % m.groups()27 else:28 raise exception.UnsupporterInterpreter(29 'TOX-EDM cannot infer version from {!r}'.format(name))30 edm = venv.getcommandpath('edm', venv=False)31 action.venv.envconfig.whitelist_externals.append(32 os.path.dirname(edm))33 if action.activity == 'recreate':34 action.popen([35 edm, 'envs', 'create', action.venvname,36 '--force', '--version', version])37 elif not env_exists(edm, action.venvname):38 action.popen([39 edm, 'envs', 'create', action.venvname,40 '--version', version])41 prefix = action.popen(42 [edm, 'prefix', '-e', action.venvname],43 redirect=False, returnout=True)44 prefix = prefix.strip()45 # The envbindir will be used to find the environment python46 # So we have to make sure that it has the right value.47 action.venv.envconfig.envbindir = prefix48 action.venv.envconfig.whitelist_externals.append(prefix)49 return True50@hookimpl51def tox_testenv_install_deps(venv, action):52 deps = venv._getresolvedeps()53 name = action.venvname54 if len(deps) > 0:55 edm = venv.getcommandpath('edm', venv=False)56 depinfo = " ".join(map(str, deps))57 action.setactivity("installdeps", "%s" % depinfo)58 args = [edm, 'install', '-e', name, '-y'] + map(str, deps)59 action.popen(args)60 return True61@hookimpl62def tox_runenvreport(venv, action):63 edm = venv.getcommandpath('edm', venv=True)64 output = action.popen([65 edm, 'run', '-e', action.venvname, '--',66 'pip', 'freeze'])67 output = output.split("\n\n")[-1]68 return output.strip().splitlines()69@hookimpl70def tox_runtest_pre(venv):71 return True72@hookimpl73def tox_runtest_post(venv):74 return True75@hookimpl76def tox_runtest(venv, redirect):77 session = venv.session78 envconfig = venv.envconfig79 action = session.newaction(venv, "runtests")80 with action:81 venv.status = 082 session.make_emptydir(envconfig.envtmpdir)83 envconfig.envtmpdir.ensure(dir=1)84 env = venv._getenv(testcommand=True)85 cwd = envconfig.changedir86 edm = venv.getcommandpath('edm', venv=True)87 action.setactivity(88 "runtests", "PYTHONHASHSEED={!r}".format(89 env.get("PYTHONHASHSEED")))90 for i, argv in enumerate(envconfig.commands):91 message = "commands[%s] | %s" % (92 i, ' '.join([str(x) for x in argv]))93 action.setactivity("runtests", message)94 ignore_return = argv[0].startswith("-")95 if ignore_return:96 if argv[0] == "-":97 del argv[0]98 else:99 argv[0] = argv[0].lstrip("-")100 argv = [edm, 'run', '-e', action.venvname, '--'] + argv101 try:102 action.popen(103 argv, cwd=cwd, env=env, redirect=redirect,104 ignore_ret=ignore_return)105 except exception.InvocationError as error:106 if envconfig.ignore_outcome:107 session.report.warning(COMMAND_FAILED.format(error))108 venv.status = "ignored failed command"109 continue # keep processing commands110 session.report.error(str(error))111 venv.status = "commands failed"112 if not envconfig.ignore_errors:113 break # Don't process remaining commands114 except KeyboardInterrupt:115 venv.status = "keyboardinterrupt"116 session.report.error(venv.status)117 raise118 return True119@hookimpl120def tox_get_python_executable(envconfig):121 venv = VirtualEnv(envconfig=envconfig)122 edm = venv.getcommandpath('edm', venv=False)123 if env_exists(edm, envconfig.envname):124 executable = subprocess.check_output([125 str(edm), 'run', '-e', envconfig.envname, '--',126 'python', '-c',127 "import sys; sys.stdout.write(sys.executable)"])128 executable = executable.strip()129 if sys.platform.startswith('win'):130 # Make sure that we always have the right bin directory131 envconfig.envbindir = os.path.join(132 os.path.dirname(executable), 'Scripts')133 return os.path.abspath(executable)134 else:...

Full Screen

Full Screen

tox-12.py

Source:tox-12.py Github

copy

Full Screen

1[testenv:py27-wheel]2skip_install = True3deps =4 coverage5 Twisted6 wheel7 gather8commands =9 mkdir -p {envtmpdir}/dist10 pip wheel . --no-deps --wheel-dir {envtmpdir}/dist11 sh -c "pip install --no-index {envtmpdir}/dist/*.whl"12 coverage run {envbindir}/trial \13 --temp-directory build/_trial_temp {posargs:ncolony}14 coverage report --include */site-packages/ncolony* \15 --omit */tests/*,*/interfaces*,*/_version* \...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run tox automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful