Skip to content

Commit e754a2a

Browse files
author
Takashi Matsuo
committed
simplified the noxfile-template
1 parent a2684bc commit e754a2a

File tree

4 files changed

+35
-52
lines changed

4 files changed

+35
-52
lines changed

.kokoro/tests/run_tests.sh

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,11 @@ SECRETS_PASSWORD=$(cat "${KOKORO_GFILE_DIR}/secrets-password.txt")
4343

4444
source ./testing/test-env.sh
4545
export GOOGLE_APPLICATION_CREDENTIALS=$(pwd)/testing/service-account.json
46+
47+
# For cloud-run session, we activate the service account for gcloud sdk.
48+
gcloud auth activate-service-account \
49+
--key-file "${GOOGLE_APPLICATION_CREDENTIALS}"
50+
4651
export GOOGLE_CLIENT_SECRETS=$(pwd)/testing/client-secrets.json
4752
source "${KOKORO_GFILE_DIR}/automl_secrets.txt"
4853
cp "${KOKORO_GFILE_DIR}/functions-slack-config.json" "functions/slack/config.json"
@@ -130,4 +135,4 @@ cd "$ROOT"
130135
# Workaround for Kokoro permissions issue: delete secrets
131136
rm testing/{test-env.sh,client-secrets.json,service-account.json}
132137

133-
exit "$RTN"
138+
exit "$RTN"

monitoring/api/v3/alerts-client/noxfile_config.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,10 @@
2929
# 'cloud_run' # Test session for Cloud Run application.
3030
'opt_in_sessions': [],
3131

32-
# Only relevant for the `cloud_run` session. Specify the file
33-
# names for your e2e test.
34-
'cloud_run_e2e_test_files': ['e2e_test.py'],
35-
3632
# An envvar key for determining the project id to use. Change it
37-
# to 'BUILD_SPECIFIC_GCLOUD_PROJECT' if you want to opt in using
38-
# a build specific Cloud project.
33+
# to 'BUILD_SPECIFIC_GCLOUD_PROJECT' if you want to opt in using a
34+
# build specific Cloud project. You can also use your own string
35+
# to use your own Cloud project.
3936
# 'gcloud_project_env': 'GCLOUD_PROJECT',
4037
'gcloud_project_env': 'BUILD_SPECIFIC_GCLOUD_PROJECT',
4138

noxfile-template.py

Lines changed: 23 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,10 @@
4444
# 'cloud_run' # Test session for Cloud Run application.
4545
'opt_in_sessions': [],
4646

47-
# Only relevant for the `cloud_run` session. Specify the file
48-
# names for your e2e test.
49-
'cloud_run_e2e_test_files': ['e2e_test.py'],
50-
5147
# An envvar key for determining the project id to use. Change it
52-
# to 'BUILD_SPECIFIC_GCLOUD_PROJECT' if you want to opt in using
53-
# a build specific Cloud project.
48+
# to 'BUILD_SPECIFIC_GCLOUD_PROJECT' if you want to opt in using a
49+
# build specific Cloud project. You can also use your own string
50+
# to use your own Cloud project.
5451
'gcloud_project_env': 'GCLOUD_PROJECT',
5552
# 'gcloud_project_env': 'BUILD_SPECIFIC_GCLOUD_PROJECT',
5653

@@ -143,11 +140,25 @@ def lint(session):
143140
session.install("flake8", "flake8-import-order")
144141

145142
local_names = _determine_local_import_names(".")
146-
args = FLAKE8_COMMON_ARGS + [
143+
options = [
147144
"--application-import-names",
148-
",".join(local_names),
149-
".",
145+
",".join(local_names)
150146
]
147+
148+
# We currently look at pytest.ini for flake8 config.
149+
# You can add your own exclude and ignore by using `extend-`
150+
#
151+
# Example config:
152+
# [flake8]
153+
# extend-ignore = I100
154+
# extend-exclude = myapp1,myapp2
155+
if os.path.isfile("pytest.ini"):
156+
options += [
157+
"--append-config",
158+
"pytest.ini",
159+
]
160+
options.append(".")
161+
args = FLAKE8_COMMON_ARGS + options
151162
session.run("flake8", *args)
152163

153164

@@ -199,37 +210,10 @@ def py(session):
199210
@nox.session
200211
def cloud_run(session):
201212
"""Run tests for cloud run."""
202-
if 'cloud_run' not in TEST_CONFIG['opt_in_sessions']:
213+
if 'cloud_run' in TEST_CONFIG['opt_in_sessions']:
214+
_session_tests(session)
215+
else:
203216
session.skip('SKIPPED: cloud_run tests are disabled for this sample.')
204-
return
205-
206-
if os.path.exists("requirements.txt"):
207-
session.install("-r", "requirements.txt")
208-
209-
if os.path.exists("requirements-test.txt"):
210-
session.install("-r", "requirements-test.txt")
211-
212-
user_envs = get_pytest_env_vars()
213-
214-
# Activate service account on Kokoro.
215-
if os.environ.get("KOKORO_JOB_NAME"):
216-
# Activate service account
217-
key_file = os.environ['GOOGLE_APPLICATION_CREDENTIALS']
218-
session.run(
219-
"gcloud", "auth", "activate-service-account",
220-
"--key-file={}".format(key_file)
221-
)
222-
223-
test_files = TEST_CONFIG['cloud_run_e2e_test_files']
224-
session.run(
225-
"pytest",
226-
*(PYTEST_COMMON_ARGS + session.posargs + test_files),
227-
# Pytest will return 5 when no tests are collected. This can happen
228-
# on travis where slow and flaky tests are excluded.
229-
# See http://doc.pytest.org/en/latest/_modules/_pytest/main.html
230-
success_codes=[0, 5],
231-
env=user_envs
232-
)
233217

234218
#
235219
# Readmegen

noxfile_config.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,10 @@
2929
# 'cloud_run' # Test session for Cloud Run application.
3030
'opt_in_sessions': [],
3131

32-
# Only relevant for the `cloud_run` session. Specify the file
33-
# names for your e2e test.
34-
'cloud_run_e2e_test_files': ['e2e_test.py'],
35-
3632
# An envvar key for determining the project id to use. Change it
37-
# to 'BUILD_SPECIFIC_GCLOUD_PROJECT' if you want to opt in using
38-
# a build specific Cloud project.
33+
# to 'BUILD_SPECIFIC_GCLOUD_PROJECT' if you want to opt in using a
34+
# build specific Cloud project. You can also use your own string
35+
# to use your own Cloud project.
3936
'gcloud_project_env': 'GCLOUD_PROJECT',
4037
# 'gcloud_project_env': 'BUILD_SPECIFIC_GCLOUD_PROJECT',
4138

0 commit comments

Comments
 (0)