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

output errors on the error stream #664

Merged
merged 1 commit into from
Mar 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions robotidy/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def transform_files(self):
self.output_diff(model_path, old_model, new_model)
changed_files += 1
except DataError as err:
click.echo(f"Failed to decode {source} with an error: {err}\nSkipping file")
click.echo(f"Failed to decode {source} with an error: {err}\nSkipping file", err=True)
changed_files = previous_changed_files
skipped_files += 1
return self.formatting_result(all_files, changed_files, skipped_files, stdin)
Expand All @@ -78,8 +78,8 @@ def formatting_result(self, all_files: int, changed_files: int, skipped_files: i
future_tense = "" if self.config.overwrite else " would be"
click.echo(
f"\n{changed_files} file{changed_files_plurar}{future_tense} reformatted, "
f"{all_files} file{all_files_plurar}{future_tense} left unchanged." +
(f" {skipped_files} file{skipped_files_plurar}{future_tense} skipped." if skipped_files else "")
f"{all_files} file{all_files_plurar}{future_tense} left unchanged."
+ (f" {skipped_files} file{skipped_files_plurar}{future_tense} skipped." if skipped_files else "")
)
if not self.config.check or not changed_files:
return 0
Expand Down
2 changes: 1 addition & 1 deletion robotidy/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ def print_description(name: str, target_version: int):
else:
rec_finder = misc.RecommendationFinder()
similar = rec_finder.find_similar(name, transformer_by_names.keys())
click.echo(f"Transformer with the name '{name}' does not exist.{similar}")
click.echo(f"Transformer with the name '{name}' does not exist.{similar}", err=True)
return 1
return 0

Expand Down
6 changes: 4 additions & 2 deletions robotidy/transformers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -451,14 +451,16 @@ def can_run_in_robot_version(transformer, overwritten, target_version):
click.echo(
f"{transformer.__class__.__name__} transformer requires Robot Framework {transformer.MIN_VERSION}.* "
f"version but you have {misc.ROBOT_VERSION} installed. "
f"Upgrade installed Robot Framework if you want to use this transformer."
f"Upgrade installed Robot Framework if you want to use this transformer.",
err=True,
)
else:
click.echo(
f"{transformer.__class__.__name__} transformer requires Robot Framework {transformer.MIN_VERSION}.* "
f"version but you set --target-version rf{target_version}. "
f"Set --target-version to rf{transformer.MIN_VERSION} or do not forcefully enable this transformer "
f"with --transform / enable parameter."
f"with --transform / enable parameter.",
err=True,
)
return False

Expand Down
4 changes: 2 additions & 2 deletions tests/atest/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def run_tidy(
):
if not self.enabled_in_version(target_version):
pytest.skip(f"Test enabled only for RF {target_version}")
runner = CliRunner()
runner = CliRunner(mix_stderr=False)
output_path = str(self.TRANSFORMERS_DIR / "actual" / source)
arguments = ["--output", output_path]
if not_modified:
Expand Down Expand Up @@ -116,7 +116,7 @@ class MultipleConfigsTest:
ROOT_DIR = Path(__file__).parent / "configuration_files"

def run_tidy(self, tmpdir, args: List[str] = None, exit_code: int = 0, not_modified: bool = False):
runner = CliRunner()
runner = CliRunner(mix_stderr=False)
temporary_dir = tmpdir / self.TEST_DIR
shutil.copytree(self.ROOT_DIR / self.TEST_DIR / "source", temporary_dir)
arguments = []
Expand Down
2 changes: 1 addition & 1 deletion tests/e2e/test_transform_stability.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@
def run_tidy(cmd, enable_disabled: bool):
if enable_disabled:
cmd = get_enable_disabled_config() + cmd
runner = CliRunner()
runner = CliRunner(mix_stderr=False)
return runner.invoke(cli, cmd)


Expand Down
6 changes: 3 additions & 3 deletions tests/utest/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ def test_describe_invalid_transformer(self, name, similar):
expected_output = f"Transformer with the name '{name}' does not exist.{similar}"
args = f"--desc {name} -".split()
result = run_tidy(args, exit_code=1)
assert expected_output in str(result.output)
assert expected_output in str(result.stderr)

@pytest.mark.parametrize("flag", ["--help", "-h"])
def test_help(self, flag):
Expand Down Expand Up @@ -357,8 +357,8 @@ def test_read_only_file(self):
source.chmod(0o400)
# overwrite input which is read-only file
result = run_tidy([str(source)], overwrite_input=True)
assert "Permission denied" in result.output
assert "\n0 files reformatted, 0 files left unchanged. 1 file skipped.\n" in result.output
assert "Permission denied" in result.stderr
assert "\n0 files reformatted, 0 files left unchanged. 1 file skipped.\n" in result.stdout

@pytest.mark.parametrize("color_flag", ["--color", "--no-color", None])
@pytest.mark.parametrize("color_env", [True, False])
Expand Down
2 changes: 1 addition & 1 deletion tests/utest/test_load_transformers.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ def test_overwriting_disabled_in_version(self, target_version, version, transfor
]
expected_output = "".join(expected_output)
output = capsys.readouterr()
assert output.out == expected_output
assert output.err == expected_output

@pytest.mark.parametrize(
"transform, warn_on",
Expand Down
2 changes: 1 addition & 1 deletion tests/utest/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def run_tidy(
std_in: Optional = None,
overwrite_input: bool = False,
):
runner = CliRunner()
runner = CliRunner(mix_stderr=False)
arguments = args if args is not None else []
if not overwrite_input:
if output:
Expand Down
Loading