Skip to content

Commit

Permalink
fix,test: run stdout tests in a temporary repo
Browse files Browse the repository at this point in the history
  • Loading branch information
akaihola committed Aug 9, 2024
1 parent 000628b commit fd5fce4
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/darker/tests/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -946,15 +946,18 @@ def test_stdout_path_resolution(git_repo, capsys):


@pytest.mark.parametrize("newline", ["\n", "\r\n"], ids=["unix", "windows"])
def test_stdout_newlines(tmp_path, monkeypatch, capsysbinary, newline):
def test_stdout_newlines(git_repo, monkeypatch, capsysbinary, newline):
"""When using ``--stdout``, newlines are not duplicated.
See: https://github.com/akaihola/darker/issues/604
The `git_repo` fixture is used to ensure that the test doesn't run in the Darker
repository clone in CI. It helps avoid the Git error message
"fatal: Not a valid object name origin/master" in the NixOS CI tests.
"""
if WINDOWS and sys.version_info < (3, 10):
# See https://bugs.python.org/issue38671
monkeypatch.chdir(tmp_path)
Path("new-file.py").touch()
code = f"import collections{newline}import sys{newline}".encode()
with patch("sys.stdin.buffer.read", return_value=code):
Expand All @@ -968,15 +971,18 @@ def test_stdout_newlines(tmp_path, monkeypatch, capsysbinary, newline):


@pytest.mark.parametrize("newline", ["\n", "\r\n"], ids=["unix", "windows"])
def test_stdout_newlines_subprocess(tmp_path, monkeypatch, newline):
def test_stdout_newlines_subprocess(git_repo, monkeypatch, newline):
"""When using ``--stdout``, newlines are not duplicated.
See: https://github.com/akaihola/darker/issues/604
The `git_repo` fixture is used to ensure that the test doesn't run in the Darker
repository clone in CI. It helps avoid the Git error message
"fatal: Not a valid object name origin/master" in the NixOS CI tests.
"""
if WINDOWS and sys.version_info < (3, 10):
# See https://bugs.python.org/issue38671
monkeypatch.chdir(tmp_path)
Path("new-file.py").touch()
code = f"import collections{newline}import sys{newline}".encode()
try:
Expand Down

0 comments on commit fd5fce4

Please sign in to comment.