How to use current_tox_py method in tox

Best Python code snippet using tox_python

_pytestplugin.py

Source:_pytestplugin.py Github

copy

Full Screen

...400 return session401 monkeypatch.setattr(tox.session, "build_session", build_session)402 return res403@pytest.fixture(scope="session")404def current_tox_py():405 """generate the current (test runners) python versions key406 e.g. py37 when running under Python 3.7"""...

Full Screen

Full Screen

test_plugin.py

Source:test_plugin.py Github

copy

Full Screen

1import shutil2import pytest3from light_the_torch.computation_backend import CPUBackend4@pytest.fixture5def patch_extract_dists(mocker):6 def patch_extract_dists_(return_value=None):7 if return_value is None:8 return_value = []9 return mocker.patch(10 "tox_ltt.plugin.ltt.extract_dists", return_value=return_value11 )12 return patch_extract_dists_13@pytest.fixture14def patch_find_links(mocker):15 def patch_find_links_(return_value=None):16 if return_value is None:17 return_value = []18 return mocker.patch("tox_ltt.plugin.ltt.find_links", return_value=return_value)19 return patch_find_links_20@pytest.fixture21def install_mock(mocker):22 return mocker.patch("tox.venv.VirtualEnv.run_install_command")23def get_pyproject_toml():24 return """25 [build-system]26 requires = ["setuptools", "wheel"]27 build-backend = "setuptools.build_meta"28 """29def get_setup_py():30 return """31 from setuptools import setup32 setup()33 """34def get_setup_cfg(name, version, install_requires=None, extra_requires=None):35 lines = ["[metadata]", f"name = {name}", f"version = {version}"]36 if install_requires is not None:37 lines.extend(("[options]", "install_requires = "))38 lines.extend([f"\t{req}" for req in install_requires])39 if extra_requires is not None:40 lines.extend(("[options.extras_require]", "extra = "))41 lines.extend([f"\t{req}" for req in extra_requires])42 return "\n".join(lines)43def get_tox_ini(44 basepython=None,45 disable_light_the_torch=None,46 pytorch_channel=None,47 pytorch_force_cpu=None,48 force_cpu=None,49 deps=None,50 skip_install=False,51 usedevelop=False,52 extra=False,53 pep517=True,54):55 lines = ["[tox]", "envlist = py"]56 if pep517:57 lines.append("isolated_build = True")58 lines.extend(("[testenv]", "requires = ", "\ttox-ltt",))59 if basepython is not None:60 lines.append(f"basepython = {basepython}")61 if skip_install:62 lines.append("skip_install = True")63 if usedevelop:64 lines.append("usedevelop = True")65 if extra:66 lines.append("extras = extra")67 if disable_light_the_torch is not None:68 lines.append(f"disable_light_the_torch = {disable_light_the_torch}")69 if pytorch_channel is not None:70 lines.append(f"pytorch_channel = {pytorch_channel}")71 if pytorch_force_cpu is not None:72 lines.append(f"pytorch_force_cpu = {pytorch_force_cpu}")73 if force_cpu is not None:74 lines.append(f"force_cpu = {force_cpu}")75 if deps is not None:76 lines.append("deps = ")77 lines.extend([f"\t{dep}" for dep in deps])78 return "\n".join(lines)79@pytest.fixture80def tox_ltt_initproj(initproj):81 def tox_ltt_initproj_(82 name="foo",83 version="1.2.3",84 basepython=None,85 install_requires=None,86 extra_requires=None,87 disable_light_the_torch=None,88 pytorch_channel=None,89 pytorch_force_cpu=None,90 force_cpu=None,91 deps=None,92 skip_install=False,93 usedevelop=False,94 pep517=True,95 ):96 filedefs = {97 "setup.cfg": get_setup_cfg(98 name,99 version,100 install_requires=install_requires,101 extra_requires=extra_requires,102 ),103 "tox.ini": get_tox_ini(104 basepython=basepython,105 skip_install=skip_install,106 usedevelop=usedevelop,107 extra=extra_requires is not None,108 disable_light_the_torch=disable_light_the_torch,109 pytorch_channel=pytorch_channel,110 pytorch_force_cpu=pytorch_force_cpu,111 force_cpu=force_cpu,112 deps=deps,113 pep517=pep517,114 ),115 }116 if pep517:117 filedefs["pyproject.toml"] = get_pyproject_toml()118 else:119 filedefs["setup.py"] = get_setup_py()120 return initproj(121 f"{name}-{version}", filedefs=filedefs, add_missing_setup_py=False122 )123 return tox_ltt_initproj_124def test_help_ini(cmd):125 result = cmd("--help-ini")126 result.assert_success(is_run_test_env=False)127 assert "disable_light_the_torch" in result.out128 assert "pytorch_channel" in result.out129 assert "pytorch_force_cpu" in result.out130@pytest.mark.slow131def test_tox_ltt_disabled(patch_extract_dists, tox_ltt_initproj, cmd):132 mock = patch_extract_dists()133 tox_ltt_initproj(disable_light_the_torch=True)134 result = cmd()135 result.assert_success(is_run_test_env=False)136 mock.assert_not_called()137@pytest.mark.slow138def test_tox_ltt_pytorch_channel(patch_find_links, tox_ltt_initproj, cmd, install_mock):139 channel = "channel"140 mock = patch_find_links()141 tox_ltt_initproj(deps=("torch",), pytorch_channel=channel)142 result = cmd()143 result.assert_success(is_run_test_env=False)144 _, kwargs = mock.call_args145 assert kwargs["channel"] == channel146@pytest.mark.slow147def test_tox_ltt_pytorch_force_cpu(148 patch_find_links, tox_ltt_initproj, cmd, install_mock149):150 mock = patch_find_links()151 tox_ltt_initproj(deps=("torch",), pytorch_force_cpu=True)152 result = cmd()153 result.assert_success(is_run_test_env=False)154 _, kwargs = mock.call_args155 assert kwargs["computation_backends"] == CPUBackend()156@pytest.mark.slow157def test_tox_ltt_force_cpu_legacy(158 patch_find_links, tox_ltt_initproj, cmd, install_mock159):160 mock = patch_find_links()161 tox_ltt_initproj(deps=("torch",), force_cpu=True)162 result = cmd()163 result.assert_success(is_run_test_env=False)164 _, kwargs = mock.call_args165 assert kwargs["computation_backends"] == CPUBackend()166def test_tox_ltt_no_requirements(167 patch_extract_dists, tox_ltt_initproj, cmd, install_mock168):169 mock = patch_extract_dists()170 tox_ltt_initproj(skip_install=True)171 result = cmd()172 result.assert_success(is_run_test_env=False)173 mock.assert_not_called()174@pytest.mark.slow175def test_tox_ltt_no_pytorch_dists(176 patch_find_links, tox_ltt_initproj, cmd, install_mock177):178 mock = patch_find_links()179 deps = ("light-the-torch",)180 tox_ltt_initproj(deps=deps)181 result = cmd()182 result.assert_success(is_run_test_env=False)183 mock.assert_not_called()184@pytest.mark.slow185def test_tox_ltt_direct_pytorch_dists(186 patch_find_links, tox_ltt_initproj, cmd, install_mock187):188 mock = patch_find_links()189 deps = ("torch", "torchaudio", "torchtext", "torchvision")190 dists = set(deps)191 tox_ltt_initproj(deps=deps)192 result = cmd()193 result.assert_success(is_run_test_env=False)194 args, _ = mock.call_args195 assert set(args[0]) == dists196@pytest.mark.slow197def test_tox_ltt_indirect_pytorch_dists(198 patch_find_links, tox_ltt_initproj, cmd, install_mock199):200 mock = patch_find_links()201 deps = ("git+https://github.com/pmeier/pystiche@v0.5.0",)202 dists = {"torch>=1.5.0", "torchvision>=0.6.0"}203 tox_ltt_initproj(deps=deps)204 result = cmd()205 result.assert_success(is_run_test_env=False)206 args, _ = mock.call_args207 assert set(args[0]) == dists208def test_tox_ltt_project_pytorch_dists(209 subtests, patch_find_links, tox_ltt_initproj, cmd, install_mock210):211 mock = patch_find_links()212 install_requires = ("torch>=1.5.0", "torchvision>=0.6.0")213 dists = set(install_requires)214 for pep517 in (True, False):215 mock.reset()216 with subtests.test(pep517=pep517):217 tox_ltt_initproj(install_requires=install_requires, pep517=pep517)218 result = cmd()219 result.assert_success(is_run_test_env=False)220 args, _ = mock.call_args221 assert set(args[0]) == dists222def test_tox_ltt_project_extra_pytorch_dists(223 subtests, patch_find_links, tox_ltt_initproj, cmd, install_mock224):225 mock = patch_find_links()226 extra_requires = ("torch>=1.5.0", "torchvision>=0.6.0")227 dists = set(extra_requires)228 for pep517 in (True, False):229 mock.reset()230 with subtests.test(pep517=pep517):231 tox_ltt_initproj(extra_requires=extra_requires, pep517=pep517)232 result = cmd()233 result.assert_success(is_run_test_env=False)234 args, _ = mock.call_args235 assert set(args[0]) == dists236def test_tox_ltt_project_usedevelop(237 patch_find_links, tox_ltt_initproj, cmd, install_mock238):239 mock = patch_find_links()240 install_requires = ("torch>=1.5.0", "torchvision>=0.6.0")241 dists = set(install_requires)242 tox_ltt_initproj(install_requires=install_requires, usedevelop=True, pep517=False)243 result = cmd()244 result.assert_success(is_run_test_env=False)245 args, _ = mock.call_args246 assert set(args[0]) == dists247@pytest.fixture248def other_basepythons(current_tox_py):249 current_minor = int(current_tox_py[-1])250 basepythons = (f"python3.{minor}" for minor in {6, 7, 8} - {current_minor})251 return [252 basepython for basepython in basepythons if shutil.which(basepython) is not None253 ]254@pytest.mark.slow255def test_tox_ltt_other_basepython(256 subtests,257 mock_venv,258 patch_extract_dists,259 patch_find_links,260 install_mock,261 tox_ltt_initproj,262 cmd,263 other_basepythons,264):265 def canonical_to_tox(version):266 major, minor, _ = version.split(".")267 return f"python{major}.{minor}"268 deps = ["torch"]269 patch_extract_dists(return_value=deps)270 mock = patch_find_links()271 for basepython in other_basepythons:272 mock.reset()273 with subtests.test(basepython=basepython):274 tox_ltt_initproj(basepython=basepython, deps=deps)275 result = cmd()276 result.assert_success()277 _, kwargs = mock.call_args278 python_version = kwargs["python_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