Skip to content

Commit

Permalink
chore: yield-from instead of python2 workaround.
Browse files Browse the repository at this point in the history
  • Loading branch information
DanCardin committed Feb 13, 2022
1 parent 98fdb18 commit cbd4b89
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 18 deletions.
4 changes: 2 additions & 2 deletions src/pytest_mock_resources/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ def is_docker_host():
return True


def get_env_config(name, kind):
def get_env_config(name, kind, default=None):
env_var = "PMR_{name}_{kind}".format(name=name.upper(), kind=kind.upper())
return os.environ.get(env_var)
return os.environ.get(env_var, default)


def fallback(fn):
Expand Down
8 changes: 6 additions & 2 deletions src/pytest_mock_resources/container/mongo.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,9 @@ def check_mongo_fn(config):

@pytest.fixture(scope="session")
def _mongo_container(pmr_mongo_config):
result = get_container(pmr_mongo_config, {27017: pmr_mongo_config.port}, {}, check_mongo_fn)
yield next(iter(result))
yield from get_container(
pmr_mongo_config,
ports={27017: pmr_mongo_config.port},
environment={},
check_fn=check_mongo_fn,
)
10 changes: 4 additions & 6 deletions src/pytest_mock_resources/container/mysql.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,14 +93,12 @@ def check_mysql_fn(config):

@pytest.fixture(scope="session")
def _mysql_container(pmr_mysql_config):
result = get_container(
yield from get_container(
pmr_mysql_config,
{3306: pmr_mysql_config.port},
{
ports={3306: pmr_mysql_config.port},
environment={
"MYSQL_DATABASE": pmr_mysql_config.root_database,
"MYSQL_ROOT_PASSWORD": pmr_mysql_config.password,
},
check_mysql_fn,
check_fn=check_mysql_fn,
)

yield next(iter(result))
10 changes: 4 additions & 6 deletions src/pytest_mock_resources/container/postgres.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,15 +83,13 @@ def check_postgres_fn(config):

@pytest.fixture(scope="session")
def _postgres_container(pmr_postgres_config):
result = get_container(
yield from get_container(
pmr_postgres_config,
{5432: pmr_postgres_config.port},
{
ports={5432: pmr_postgres_config.port},
environment={
"POSTGRES_DB": pmr_postgres_config.root_database,
"POSTGRES_USER": pmr_postgres_config.username,
"POSTGRES_PASSWORD": pmr_postgres_config.password,
},
check_postgres_fn,
check_fn=check_postgres_fn,
)

yield next(iter(result))
3 changes: 1 addition & 2 deletions src/pytest_mock_resources/container/redis.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,9 @@ def check_redis_fn(config):

@pytest.fixture(scope="session")
def _redis_container(pmr_redis_config):
result = get_container(
yield from get_container(
pmr_redis_config,
ports={6379: pmr_redis_config.port},
environment={},
check_fn=check_redis_fn,
)
yield next(iter(result))

0 comments on commit cbd4b89

Please sign in to comment.