How to use pip_pre method in tox

Best Python code snippet using tox_python

conftest.py

Source:conftest.py Github

copy

Full Screen

1"""2 Copyright 2022 Inmanta3 Licensed under the Apache License, Version 2.0 (the "License");4 you may not use this file except in compliance with the License.5 You may obtain a copy of the License at6 http://www.apache.org/licenses/LICENSE-2.07 Unless required by applicable law or agreed to in writing, software8 distributed under the License is distributed on an "AS IS" BASIS,9 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.10 See the License for the specific language governing permissions and11 limitations under the License.12 Contact: code@inmanta.com13"""14import os15import subprocess16import time17import uuid18import pytest19from pytest import fixture20collect_ignore = []21if os.getenv("INMANTA_TEST_INFRA_SETUP", "false").lower() == "true":22 # If the INMANTA_TEST_INFRA_SETUP is on, ignore the tests when running outside of docker except the "test_in_docker" one.23 # That test executes the rest of the tests inside a docker container24 # (and skips itself, because the environment variable will be off in the container).25 test_dir = os.path.dirname(os.path.realpath(__file__))26 test_modules = [27 module for module in os.listdir(test_dir) if "test_in_docker" not in module28 ]29 collect_ignore += test_modules30@pytest.fixture(scope="function")31def docker_container() -> None:32 container_id = start_container()33 yield container_id34 stop_container(container_id)35def start_container():36 image_name = f"test-module-postgres-{uuid.uuid4()}"37 docker_build_cmd = ["sudo", "docker", "build", ".", "-t", image_name]38 pip_index_url = os.environ.get("PIP_INDEX_URL", None)39 if pip_index_url is not None:40 docker_build_cmd.append("--build-arg")41 docker_build_cmd.append(f"PIP_INDEX_URL={pip_index_url}")42 pip_pre = os.environ.get("PIP_PRE", None)43 if pip_pre is not None:44 docker_build_cmd.append("--build-arg")45 docker_build_cmd.append(f"PIP_PRE={pip_pre}")46 subprocess.run(47 docker_build_cmd,48 check=True,49 )50 container_id = (51 subprocess.run(52 [53 "sudo",54 "docker",55 "run",56 "--rm",57 "-e",58 f"POSTGRES_PASSWORD={uuid.uuid4()}",59 "-d",60 image_name,61 ],62 stdout=subprocess.PIPE,63 stderr=subprocess.PIPE,64 check=True,65 )66 .stdout.decode("utf-8")67 .strip()68 )69 wait_until_postgresql_process_is_up(container_id)70 print(f"Started container with id {container_id}")71 return container_id72def wait_until_postgresql_process_is_up(docker_container) -> None:73 """74 Execute a busy wait until the PostgreSQL process has finished starting.75 An exception is raised after 30 failed is ready checks.76 """77 retries = 3078 while retries > 0:79 try:80 subprocess.run(81 [82 "sudo",83 "docker",84 "exec",85 f"{docker_container}",86 "pg_isready",87 ],88 check=True,89 )90 except subprocess.CalledProcessError:91 retries -= 192 time.sleep(1)93 else:94 return95 raise Exception("Timeout while waiting for PostgreSQL server to start")96def stop_container(container_id: str):97 subprocess.run(98 [99 "sudo",100 "docker",101 "cp",102 f"{container_id}:/module/postgresql/junit.xml",103 "junit_docker.xml",104 ],105 check=True,106 )107 no_clean = os.getenv("INMANTA_NO_CLEAN", "false").lower() == "true"108 print(f"Skipping cleanup: {no_clean}")109 if not no_clean:110 subprocess.run(["sudo", "docker", "stop", f"{container_id}"], check=True)111@fixture(scope="function")112def pg_host():113 yield os.getenv("PG_TEST_HOST", "localhost")114@fixture115def pg_host_user():116 return os.getenv("PG_TEST_HOST_USER", "root")117@fixture118def pg_host_line(pg_host, pg_host_user):119 return f"""ip::Host(name="testhost", ip="{pg_host}", remote_agent=true, remote_user={pg_host_user})"""120@fixture121def pg_url(pg_host, pg_host_user):...

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