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

test_import_sorting.py failures when run from outside the source tree #510

Closed
akaihola opened this issue Jul 12, 2023 · 0 comments · Fixed by #583
Closed

test_import_sorting.py failures when run from outside the source tree #510

akaihola opened this issue Jul 12, 2023 · 0 comments · Fixed by #583
Assignees
Labels
bug Something isn't working
Milestone

Comments

@akaihola
Copy link
Owner

Describe the bug
When pytest is run from outside the Darker source tree, some tests fail.

To Reproduce
Steps to reproduce the behavior:

  1. Clone Darker: git clone https://github.com/akaihola/darker
  2. In a fresh virtualenv, install the cloned Darker with test dependencies: pip install './darker[test]'
  3. Run tests with pytest ./darker/src/darker/tests/test_import_sorting.py
  4. Observe test failures

Expected behavior
No test failures

Screenshots

pytest ./darker/src/darker/tests/test_import_sorting.py
================================================ test session starts ================================================
platform linux -- Python 3.11.3, pytest-7.3.1, pluggy-1.0.0
rootdir: /tmp/darker
configfile: pytest.ini
plugins: darker-0.1.2, kwparametrize-0.0.3
collected 64 items                                                                                                  

darker/src/darker/tests/test_import_sorting.py ..............................................F.F............. [ 96%]
..                                                                                                            [100%]

===================================================== FAILURES ======================================================
___________________________________ test_build_isort_args[src0-None-None-expect0] ___________________________________

src = PosixPath('file.py'), config = None, line_length = None, expect = {'settings_path': '/tmp'}

    @pytest.mark.kwparametrize(
        dict(src=Path("file.py"), expect={"settings_path": "{cwd}"}),
        dict(
            config="myconfig.toml",
            expect={"settings_file": "myconfig.toml"},
        ),
        dict(line_length=42, expect={"settings_path": "{cwd}", "line_length": 42}),
        src=Path("file.py"),
        config=None,
        line_length=None,
    )
    def test_build_isort_args(src, config, line_length, expect):
        """``_build_isort_args`` returns correct arguments for isort"""
        result = darker.import_sorting._build_isort_args(src, config, line_length)
    
        if "settings_path" in expect:
            expect["settings_path"] = str(expect["settings_path"].format(cwd=Path.cwd()))
>       assert result == expect
E       AssertionError: assert {'settings_path': '/'} == {'settings_path': '/tmp'}
E         Differing items:
E         {'settings_path': '/'} != {'settings_path': '/tmp'}
E         Use -v to get more diff

darker/src/darker/tests/test_import_sorting.py:184: AssertionError
____________________________________ test_build_isort_args[src2-None-42-expect2] ____________________________________

src = PosixPath('file.py'), config = None, line_length = 42, expect = {'line_length': 42, 'settings_path': '/tmp'}

    @pytest.mark.kwparametrize(
        dict(src=Path("file.py"), expect={"settings_path": "{cwd}"}),
        dict(
            config="myconfig.toml",
            expect={"settings_file": "myconfig.toml"},
        ),
        dict(line_length=42, expect={"settings_path": "{cwd}", "line_length": 42}),
        src=Path("file.py"),
        config=None,
        line_length=None,
    )
    def test_build_isort_args(src, config, line_length, expect):
        """``_build_isort_args`` returns correct arguments for isort"""
        result = darker.import_sorting._build_isort_args(src, config, line_length)
    
        if "settings_path" in expect:
            expect["settings_path"] = str(expect["settings_path"].format(cwd=Path.cwd()))
>       assert result == expect
E       AssertionError: assert {'line_length...gs_path': '/'} == {'line_length...path': '/tmp'}
E         Omitting 1 identical items, use -vv to show
E         Differing items:
E         {'settings_path': '/'} != {'settings_path': '/tmp'}
E         Use -v to get more diff

darker/src/darker/tests/test_import_sorting.py:184: AssertionError
================================================= warnings summary ==================================================
../home/kaiant/.virtualenvs/py311/lib/python3.11/site-packages/_pytest/config/__init__.py:1302
  /home/kaiant/.virtualenvs/py311/lib/python3.11/site-packages/_pytest/config/__init__.py:1302: PytestConfigWarning: Unknown config option: show_capture
  
    self._warn_or_fail_if_strict(f"Unknown config option: {key}\n")

-- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html
=============================================== slowest 10 durations ================================================
0.02s call     src/darker/tests/test_import_sorting.py::test_apply_isort[content2-expect2-\n-utf-8]
0.02s call     src/darker/tests/test_import_sorting.py::test_apply_isort[content2-expect2-\r\n-utf-8]
0.02s call     src/darker/tests/test_import_sorting.py::test_apply_isort[content4-expect4-\n-utf-8]
0.01s call     src/darker/tests/test_import_sorting.py::test_apply_isort[content2-expect2-\n-iso-8859-1]
0.01s call     src/darker/tests/test_import_sorting.py::test_apply_isort[content4-expect4-\n-iso-8859-1]
0.01s call     src/darker/tests/test_import_sorting.py::test_apply_isort[content1-expect1-\r\n-iso-8859-1]
0.01s call     src/darker/tests/test_import_sorting.py::test_apply_isort[content3-expect3-\n-iso-8859-1]
0.01s call     src/darker/tests/test_import_sorting.py::test_apply_isort[content3-expect3-\r\n-iso-8859-1]
0.01s call     src/darker/tests/test_import_sorting.py::test_apply_isort[content3-expect3-\n-utf-8]
0.01s call     src/darker/tests/test_import_sorting.py::test_apply_isort[content2-expect2-\r\n-iso-8859-1]
============================================== short test summary info ==============================================
FAILED darker/src/darker/tests/test_import_sorting.py::test_build_isort_args[src0-None-None-expect0] - AssertionError: assert {'settings_path': '/'} == {'settings_path': '/tmp'}
FAILED darker/src/darker/tests/test_import_sorting.py::test_build_isort_args[src2-None-42-expect2] - AssertionError: assert {'line_length...gs_path': '/'} == {'line_length...path': '/tmp'}
====================================== 2 failed, 62 passed, 1 warning in 0.76s ======================================

Environment (please complete the following information):

  • OS: Linux / NixOS 21.11
  • Python version: 3.11.3
  • Darker version: 1.7.2
@akaihola akaihola added the bug Something isn't working label Jul 12, 2023
@akaihola akaihola added this to the Darker 1.8.1 milestone Jul 12, 2023
@akaihola akaihola self-assigned this Jul 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Development

Successfully merging a pull request may close this issue.

1 participant