Skip to content

Commit 7942750

Browse files
authored
Update test assertions after lifecycle output change (#408)
`lifecycle` now emits all buildpack output to stdout in order to fix this stdout/stderr output interleaving bug: buildpacks/pack#2330 buildpacks/lifecycle#1525 As such, the `libcnb-test` integration test assertions need updating to use stdout in a number of places. This also allows the test assertions to correctly assert the placement of warning in-between other non-warning content. (And in the process has revealed a couple of places where whitespace could be tweaked, which will be handled separately as part of the future build output style change work). GUS-W-19337364.
1 parent 206dbde commit 7942750

File tree

7 files changed

+163
-97
lines changed

7 files changed

+163
-97
lines changed

tests/checks_test.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,16 @@ fn checks_reject_pythonhome_env_var() {
1111

1212
TestRunner::default().build(config, |context| {
1313
assert_contains!(
14-
context.pack_stderr,
14+
context.pack_stdout,
1515
indoc! {"
1616
[Error: Unsafe environment variable found]
1717
The environment variable 'PYTHONHOME' is set, however, it can
1818
cause problems with the build so we do not allow using it.
1919
2020
You must unset that environment variable. If you didn't set it
2121
yourself, check that it wasn't set by an earlier buildpack.
22+
23+
ERROR: failed to build: exit status 1
2224
"}
2325
);
2426
});

tests/django_test.rs

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ fn django_staticfiles_legacy_django() {
3434
TestRunner::default().build(
3535
default_build_config("tests/fixtures/django_staticfiles_legacy_django"),
3636
|context| {
37-
// We can't `assert_empty!(context.pack_stderr)` here, due to the Python 3.9 deprecation warning.
37+
assert_empty!(context.pack_stderr);
3838
assert_contains!(
3939
context.pack_stdout,
4040
indoc! {"
@@ -99,11 +99,7 @@ fn django_invalid_settings_module() {
9999
context.pack_stdout,
100100
indoc! {"
101101
[Generating Django static files]
102-
"}
103-
);
104-
assert_contains!(
105-
context.pack_stderr,
106-
indoc! {"
102+
107103
[Error: Unable to inspect Django configuration]
108104
The 'python manage.py help collectstatic' Django management command
109105
(used to check whether Django's static files feature is enabled)
@@ -116,14 +112,16 @@ fn django_invalid_settings_module() {
116112
);
117113
// Full traceback omitted since it will change across Django/Python versions causing test churn.
118114
assert_contains!(
119-
context.pack_stderr,
115+
context.pack_stdout,
120116
indoc! {"
121117
ModuleNotFoundError: No module named 'nonexistent-module'
122118
123119
124120
This indicates there is a problem with your application code or Django
125121
configuration. Try running the 'manage.py' script locally to see if the
126122
same error occurs.
123+
124+
ERROR: failed to build: exit status 1
127125
"}
128126
);
129127
},
@@ -142,11 +140,15 @@ fn django_staticfiles_misconfigured() {
142140
indoc! {"
143141
[Generating Django static files]
144142
Running 'manage.py collectstatic'
143+
Traceback (most recent call last):
145144
"}
146145
);
146+
// Full traceback omitted since it will change across Django/Python versions causing test churn.
147147
assert_contains!(
148-
context.pack_stderr,
148+
context.pack_stdout,
149149
indoc! {"
150+
django.core.exceptions.ImproperlyConfigured: You're using the staticfiles app without having set the required STATIC_URL setting.
151+
150152
[Error: Unable to generate Django static files]
151153
The 'python manage.py collectstatic --noinput' Django management
152154
command to generate static files failed (exit status: 1).
@@ -162,6 +164,8 @@ fn django_staticfiles_misconfigured() {
162164
Or, if you do not need to use static files in your app, disable the
163165
Django static files feature by removing 'django.contrib.staticfiles'
164166
from 'INSTALLED_APPS' in your app's Django configuration.
167+
168+
ERROR: failed to build: exit status 1
165169
"}
166170
);
167171
},

tests/package_manager_test.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ fn no_package_manager_detected() {
1010
.expected_pack_result(PackResult::Failure),
1111
|context| {
1212
assert_contains!(
13-
context.pack_stderr,
13+
context.pack_stdout,
1414
indoc! {"
1515
[Error: Couldn't find any supported Python package manager files]
1616
Your app must have either a 'requirements.txt', 'poetry.lock'
@@ -36,6 +36,8 @@ fn no_package_manager_detected() {
3636
For help with using Python on Heroku, see:
3737
https://devcenter.heroku.com/articles/getting-started-with-python-fir
3838
https://devcenter.heroku.com/articles/python-support
39+
40+
ERROR: failed to build: exit status 1
3941
"}
4042
);
4143
},
@@ -50,7 +52,7 @@ fn multiple_package_managers_detected() {
5052
.expected_pack_result(PackResult::Failure),
5153
|context| {
5254
assert_contains!(
53-
context.pack_stderr,
55+
context.pack_stdout,
5456
indoc! {"
5557
[Error: Multiple Python package manager files were found]
5658
Exactly one package manager file must be present in your app's
@@ -67,6 +69,8 @@ fn multiple_package_managers_detected() {
6769
trying uv, since it supports lockfiles, is extremely fast, and
6870
is actively maintained by a full-time team:
6971
https://docs.astral.sh/uv/
72+
73+
ERROR: failed to build: exit status 1
7074
"}
7175
);
7276
},

tests/pip_test.rs

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ fn pip_editable_git_compiled() {
216216
config.env("WHEEL_PACKAGE_URL", "https://github.com/pypa/wheel.git");
217217

218218
TestRunner::default().build(config, |context| {
219-
// We can't `assert_empty!(context.pack_stderr)` here, since the git clone steps print to stderr.
219+
assert_empty!(context.pack_stderr);
220220
assert_contains!(
221221
context.pack_stdout,
222222
"Cloning https://github.com/pypa/wheel.git (to revision 0.44.0) to /layers/heroku_python/venv/src/extension-dist"
@@ -232,9 +232,12 @@ fn pip_oldest_python() {
232232
let config = default_build_config("tests/fixtures/pip_oldest_python");
233233

234234
TestRunner::default().build(config, |context| {
235-
assert_eq!(
236-
context.pack_stderr,
235+
assert_empty!(context.pack_stderr);
236+
assert_contains!(
237+
context.pack_stdout,
237238
indoc! {"
239+
[Determining Python version]
240+
Using Python version 3.9.0 specified in .python-version
238241
239242
[Warning: Support for Python 3.9 is deprecated]
240243
Python 3.9 will reach its upstream end-of-life in October 2025,
@@ -250,14 +253,7 @@ fn pip_oldest_python() {
250253
For more information, see:
251254
https://devcenter.heroku.com/articles/python-support#supported-python-versions
252255
253-
"}
254-
);
255-
assert_contains!(
256-
context.pack_stdout,
257-
indoc! {"
258-
[Determining Python version]
259-
Using Python version 3.9.0 specified in .python-version
260-
256+
261257
[Installing Python]
262258
Installing Python 3.9.0
263259
"}
@@ -272,19 +268,12 @@ fn pip_install_error() {
272268
config.expected_pack_result(PackResult::Failure);
273269

274270
TestRunner::default().build(config, |context| {
275-
// Ideally we could test a combined stdout/stderr, however libcnb-test doesn't support this:
276-
// https://github.com/heroku/libcnb.rs/issues/536
277271
assert_contains!(
278272
context.pack_stdout,
279273
indoc! {"
280274
[Installing dependencies using pip]
281275
Creating virtual environment
282276
Running 'pip install -r requirements.txt'
283-
"}
284-
);
285-
assert_contains!(
286-
context.pack_stderr,
287-
indoc! {"
288277
ERROR: Invalid requirement: 'an-invalid-requirement!': Expected end or semicolon (after name and no valid version specifier)
289278
an-invalid-requirement!
290279
^ (from line 1 of requirements.txt)
@@ -294,6 +283,8 @@ fn pip_install_error() {
294283
dependencies failed (exit status: 1).
295284
296285
See the log output above for more information.
286+
287+
ERROR: failed to build: exit status 1
297288
"}
298289
);
299290
});

tests/poetry_test.rs

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -234,12 +234,27 @@ fn poetry_oldest_python() {
234234
let config = default_build_config("tests/fixtures/poetry_oldest_python");
235235

236236
TestRunner::default().build(config, |context| {
237-
// We can't `assert_empty!(context.pack_stderr)` here, due to the Python 3.9 deprecation warning.
237+
assert_empty!(context.pack_stderr);
238238
assert_contains!(
239239
context.pack_stdout,
240240
&formatdoc! {"
241241
[Determining Python version]
242242
Using Python version 3.9.0 specified in .python-version
243+
244+
[Warning: Support for Python 3.9 is deprecated]
245+
Python 3.9 will reach its upstream end-of-life in October 2025,
246+
at which point it will no longer receive security updates:
247+
https://devguide.python.org/versions/#supported-versions
248+
249+
As such, support for Python 3.9 will be removed from this
250+
buildpack on 7th January 2026.
251+
252+
Upgrade to a newer Python version as soon as possible, by
253+
changing the version in your .python-version file.
254+
255+
For more information, see:
256+
https://devcenter.heroku.com/articles/python-support#supported-python-versions
257+
243258
244259
[Installing Python]
245260
Installing Python 3.9.0
@@ -269,19 +284,13 @@ fn poetry_mismatched_python_version() {
269284
config.expected_pack_result(PackResult::Failure);
270285

271286
TestRunner::default().build(config, |context| {
272-
// Ideally we could test a combined stdout/stderr, however libcnb-test doesn't support this:
273-
// https://github.com/heroku/libcnb.rs/issues/536
274287
assert_contains!(
275288
context.pack_stdout,
276-
indoc! {"
289+
&formatdoc! {r#"
277290
[Installing dependencies using Poetry]
278291
Creating virtual environment
279292
Running 'poetry sync --only main'
280-
"}
281-
);
282-
assert_contains!(
283-
context.pack_stderr,
284-
&formatdoc! {r#"
293+
285294
Current Python version ({DEFAULT_PYTHON_FULL_VERSION}) is not allowed by the project (3.12.*).
286295
Please change python executable via the "env use" command.
287296
@@ -290,6 +299,8 @@ fn poetry_mismatched_python_version() {
290299
dependencies failed (exit status: 1).
291300
292301
See the log output above for more information.
302+
303+
ERROR: failed to build: exit status 1
293304
"#}
294305
);
295306
});
@@ -302,27 +313,23 @@ fn poetry_lockfile_out_of_sync() {
302313
config.expected_pack_result(PackResult::Failure);
303314

304315
TestRunner::default().build(config, |context| {
305-
// Ideally we could test a combined stdout/stderr, however libcnb-test doesn't support this:
306-
// https://github.com/heroku/libcnb.rs/issues/536
307316
assert_contains!(
308317
context.pack_stdout,
309318
indoc! {"
310319
[Installing dependencies using Poetry]
311320
Creating virtual environment
312321
Running 'poetry sync --only main'
313322
Installing dependencies from lock file
314-
"}
315-
);
316-
assert_contains!(
317-
context.pack_stderr,
318-
indoc! {"
323+
319324
pyproject.toml changed significantly since poetry.lock was last generated. Run `poetry lock` to fix the lock file.
320325
321326
[Error: Unable to install dependencies using Poetry]
322327
The 'poetry sync --only main' command to install the app's
323328
dependencies failed (exit status: 1).
324329
325330
See the log output above for more information.
331+
332+
ERROR: failed to build: exit status 1
326333
"}
327334
);
328335
});

0 commit comments

Comments
 (0)