Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

disabled capturing of stderr to allow us to see cause of failure in functional tests #77

Merged
merged 1 commit into from
Aug 16, 2021

Conversation

wxtim
Copy link
Member

@wxtim wxtim commented Aug 16, 2021

Closes #71

Currently when functional test fails (often when it runs cylc validate) one has locate the pytest running that code and add breakpoints, even when the test failure relates to problems which are small or tangential to the feature in question.

By adding -s to the pytest option any failures will show the stdout from the commands run.

To test, try doing anything nasty (delete the runtime section/add an illegal config item/remove icp/change the name of a jinja2 template variable) to the flow.cylc in any of the functional test workflows and running the tests.

see also Pytest docs: How to caputure stdout/err

@wxtim wxtim requested review from kinow and MetRonnie August 16, 2021 08:43
@wxtim wxtim self-assigned this Aug 16, 2021
@wxtim wxtim added the enhancement New feature or request label Aug 16, 2021
@wxtim wxtim added this to the 1.0.0 milestone Aug 16, 2021
Copy link
Member

@MetRonnie MetRonnie left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This works ok, but another solution is to use check=True like so

--- a/tests/functional/test_pre_configure.py
+++ b/tests/functional/test_pre_configure.py
@@ -91,9 +91,7 @@ def test_validate(tmp_path, srcdir, envvars, args):
     script = ['cylc', 'validate', str(srcdir)]
     if args:
         script = script + args
-    assert (
-        run(script, env=envvars)
-    ).returncode == 0
+    run(script, env=envvars, check=True)
 

With this, pytest captures and prints the stderr after the traceback, instead of it showing up amongst the list of tests and their statuses.

If check is true, and the process exits with a non-zero exit code, a CalledProcessError exception will be raised. Attributes of that exception hold the arguments, the exit code, and stdout and stderr if they were captured.

https://docs.python.org/3.7/library/subprocess.html#subprocess.run

@wxtim
Copy link
Member Author

wxtim commented Aug 16, 2021

This works ok, but another solution is to use check=True like so

--- a/tests/functional/test_pre_configure.py
+++ b/tests/functional/test_pre_configure.py
@@ -91,9 +91,7 @@ def test_validate(tmp_path, srcdir, envvars, args):
     script = ['cylc', 'validate', str(srcdir)]
     if args:
         script = script + args
-    assert (
-        run(script, env=envvars)
-    ).returncode == 0
+    run(script, env=envvars, check=True)
 

With this, pytest captures and prints the stderr after the traceback, instead of it showing up amongst the list of tests and their statuses.

If check is true, and the process exits with a non-zero exit code, a CalledProcessError exception will be raised. Attributes of that exception hold the arguments, the exit code, and stdout and stderr if they were captured.

https://docs.python.org/3.7/library/subprocess.html#subprocess.run

Preferable, but a much bigger job: Can I suggest this, for now, but with a suggestion that we introduce your logic later.

@kinow kinow merged commit c200cbd into cylc:master Aug 16, 2021
@kinow
Copy link
Member

kinow commented Aug 16, 2021

Created follow-up issue: #78 Thanks @wxtim

@oliver-sanders oliver-sanders modified the milestones: 1.0.0, 0.3.0 Nov 9, 2021
@wxtim wxtim deleted the disable-stderr-capture branch December 1, 2022 13:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Make Functional Tests Fail Helpfully
4 participants