Skip to content

Commit 8c18cec

Browse files
author
Takashi Matsuo
authored
[appengine] use noxfile_config.py instead of pytest.ini (#4096)
also update noxfile-template.py in appengine/standard
1 parent 8d50b3a commit 8c18cec

File tree

3 files changed

+98
-3
lines changed

3 files changed

+98
-3
lines changed
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# Copyright 2020 Google LLC
2+
#
3+
# 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 at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
# Default TEST_CONFIG_OVERRIDE for python repos.
16+
17+
# You can copy this file into your directory, then it will be inported from
18+
# the noxfile.py.
19+
20+
# The source of truth:
21+
# https://github.com/GoogleCloudPlatform/python-docs-samples/blob/master/noxfile_config.py
22+
23+
TEST_CONFIG_OVERRIDE = {
24+
# You can opt out from the test for specific Python versions.
25+
'ignored_versions': ["3.6", "3.7", "3.8"],
26+
27+
# An envvar key for determining the project id to use. Change it
28+
# to 'BUILD_SPECIFIC_GCLOUD_PROJECT' if you want to opt in using a
29+
# build specific Cloud project. You can also use your own string
30+
# to use your own Cloud project.
31+
'gcloud_project_env': 'GOOGLE_CLOUD_PROJECT',
32+
# 'gcloud_project_env': 'BUILD_SPECIFIC_GCLOUD_PROJECT',
33+
34+
# A dictionary you want to inject into your test. Don't put any
35+
# secrets here. These values will override predefined values.
36+
'envs': {'DJANGO_SETTINGS_MODULE': 'mysite.settings'},
37+
}

appengine/standard/django/pytest.ini

Lines changed: 0 additions & 2 deletions
This file was deleted.

appengine/standard/noxfile-template.py

Lines changed: 61 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,69 @@
1616

1717
import os
1818
from pathlib import Path
19+
import sys
1920

2021
import nox
2122
import tempfile
2223

2324

25+
# WARNING - WARNING - WARNING - WARNING - WARNING
26+
# WARNING - WARNING - WARNING - WARNING - WARNING
27+
# DO NOT EDIT THIS FILE EVER!
28+
# WARNING - WARNING - WARNING - WARNING - WARNING
29+
# WARNING - WARNING - WARNING - WARNING - WARNING
30+
31+
# Copy `noxfile_config.py` to your directory and modify it instead.
32+
33+
# `TEST_CONFIG` dict is a configuration hook that allows users to
34+
# modify the test configurations. The values here should be in sync
35+
# with `noxfile_config.py`. Users will copy `noxfile_config.py` into
36+
# their directory and modify it.
37+
38+
TEST_CONFIG = {
39+
# You can opt out from the test for specific Python versions.
40+
'ignored_versions': ["2.7"],
41+
42+
# An envvar key for determining the project id to use. Change it
43+
# to 'BUILD_SPECIFIC_GCLOUD_PROJECT' if you want to opt in using a
44+
# build specific Cloud project. You can also use your own string
45+
# to use your own Cloud project.
46+
'gcloud_project_env': 'GOOGLE_CLOUD_PROJECT',
47+
# 'gcloud_project_env': 'BUILD_SPECIFIC_GCLOUD_PROJECT',
48+
49+
# A dictionary you want to inject into your test. Don't put any
50+
# secrets here. These values will override predefined values.
51+
'envs': {},
52+
}
53+
54+
55+
try:
56+
# Ensure we can import noxfile_config in the project's directory.
57+
sys.path.append('.')
58+
from noxfile_config import TEST_CONFIG_OVERRIDE
59+
except ImportError as e:
60+
print("No user noxfile_config found: detail: {}".format(e))
61+
TEST_CONFIG_OVERRIDE = {}
62+
63+
# Update the TEST_CONFIG with the user supplied values.
64+
TEST_CONFIG.update(TEST_CONFIG_OVERRIDE)
65+
66+
67+
def get_pytest_env_vars():
68+
"""Returns a dict for pytest invocation."""
69+
ret = {}
70+
71+
# Override the GCLOUD_PROJECT and the alias.
72+
env_key = TEST_CONFIG['gcloud_project_env']
73+
# This should error out if not set.
74+
ret['GOOGLE_CLOUD_PROJECT'] = os.environ[env_key]
75+
ret['GCLOUD_PROJECT'] = os.environ[env_key] # deprecated
76+
77+
# Apply user supplied envs.
78+
ret.update(TEST_CONFIG['envs'])
79+
return ret
80+
81+
2482
# DO NOT EDIT - automatically generated.
2583
# All versions used to tested samples.
2684
ALL_VERSIONS = ["2.7", "3.6", "3.7", "3.8"]
@@ -30,6 +88,7 @@
3088

3189
TESTED_VERSIONS = sorted([v for v in ALL_VERSIONS if v not in IGNORED_VERSIONS])
3290

91+
INSTALL_LIBRARY_FROM_SOURCE = bool(os.environ.get("INSTALL_LIBRARY_FROM_SOURCE", False))
3392
#
3493
# Style Checks
3594
#
@@ -104,7 +163,8 @@ def _session_tests(session, post_install=None):
104163
# Pytest will return 5 when no tests are collected. This can happen
105164
# on travis where slow and flaky tests are excluded.
106165
# See http://doc.pytest.org/en/latest/_modules/_pytest/main.html
107-
success_codes=[0, 5]
166+
success_codes=[0, 5],
167+
env=get_pytest_env_vars()
108168
)
109169

110170

0 commit comments

Comments
 (0)