Skip to content

[prerelease] pytest-isort and if session is None: assert parent is None #9487

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

Closed
The-Compiler opened this issue Jan 7, 2022 · 9 comments · Fixed by stephrdev/pytest-isort#40
Labels
status: help wanted developers would like help from experts on this topic type: backward compatibility might present some backward compatibility issues which should be carefully noted in the changelog

Comments

@The-Compiler
Copy link
Member

Another one from #9415 - I don't quite understand what's going on and would like some help here.

When running the tests of pytest-isort, they fail with pytest 7.0.0rc1, but they fail in three different ways when bisecting things:

After 22dad53:

pytest_isort/__init__.py:67: in pytest_collect_file
    return IsortItem.from_parent(parent, fspath=path)
../../../proj/pytest/src/_pytest/nodes.py:587: in from_parent
    return super().from_parent(parent=parent, fspath=fspath, path=path, **kw)
../../../proj/pytest/src/_pytest/nodes.py:237: in from_parent
    return cls._create(parent=parent, **kw)
../../../proj/pytest/src/_pytest/nodes.py:128: in _create
    return super().__call__(*k, **kw)
pytest_isort/__init__.py:175: in __init__
    super(IsortItem, self).__init__(name=path, parent=parent, **kwargs)
../../../proj/pytest/src/_pytest/nodes.py:621: in __init__
    super().__init__(name, parent, config, session, nodeid=nodeid)
../../../proj/pytest/src/_pytest/nodes.py:549: in __init__
    path, fspath = _imply_path(path, fspath=fspath)
../../../proj/pytest/src/_pytest/nodes.py:100: in _imply_path
    raise ValueError(
E   ValueError: Path(local('/home/florian/tmp/pytest-bisect/pytest-isort/pytest_isort/__init__.py')) != <Session pytest-isort exitstatus=<ExitCode.OK: 0> testsfailed=0 testscollected=0>
E   if both path and fspath are given they need to be equal

After d7b0e17:

pytest_isort/__init__.py:67: in pytest_collect_file
    return IsortItem.from_parent(parent, fspath=path)
../../../proj/pytest/src/_pytest/nodes.py:622: in from_parent
    return super().from_parent(parent=parent, fspath=fspath, path=path, **kw)
../../../proj/pytest/src/_pytest/nodes.py:254: in from_parent
    return cls._create(parent=parent, **kw)
../../../proj/pytest/src/_pytest/nodes.py:131: in _create
    return super().__call__(*k, **kw)
pytest_isort/__init__.py:175: in __init__
    super(IsortItem, self).__init__(name=path, parent=parent, **kwargs)
../../../proj/pytest/src/_pytest/nodes.py:671: in __init__
    super().__init__(
../../../proj/pytest/src/_pytest/nodes.py:576: in __init__
    path, fspath = _imply_path(path, fspath=fspath)
../../../proj/pytest/src/_pytest/nodes.py:112: in _imply_path
    assert fspath is not None
E   AssertionError
===================

After f87df9c (also needs 63899c7):

/home/florian/tmp/pytest-bisect/pytest-isort/tests/test_plugin.py:187: in test_init
    test_obj = IsortItem.from_parent(parent, fspath=path)
/home/florian/proj/pytest/src/_pytest/nodes.py:623: in from_parent
    return super().from_parent(parent=parent, fspath=fspath, path=path, **kw)
/home/florian/proj/pytest/src/_pytest/nodes.py:256: in from_parent
    return cls._create(parent=parent, **kw)
/home/florian/proj/pytest/src/_pytest/nodes.py:140: in _create
    return super().__call__(*k, **kw)
/home/florian/tmp/pytest-bisect/pytest-isort/pytest_isort/__init__.py:175: in __init__
    super(IsortItem, self).__init__(name=path, parent=parent, **kwargs)
/home/florian/proj/pytest/src/_pytest/nodes.py:676: in __init__
    super().__init__(
/home/florian/proj/pytest/src/_pytest/nodes.py:592: in __init__
    assert parent is not None
E   AssertionError

Note that you will need pytest-isort master (with stephrdev/pytest-isort#39 in).

This might be caused by something pytest-isort does (see its source), but honestly I'm pretty lost...

cc @RonnyPfannschmidt @bluetech @stephrdev @hroncok

@The-Compiler The-Compiler added status: help wanted developers would like help from experts on this topic type: backward compatibility might present some backward compatibility issues which should be carefully noted in the changelog labels Jan 7, 2022
@The-Compiler The-Compiler added this to the 7.0 milestone Jan 7, 2022
@RonnyPfannschmidt
Copy link
Member

It's likely related to the item + file inheritance

@stephrdev
Copy link

If there is something we can fix in pytest-isort, I'm willing to do whatever is needed maintaining backwards compatibility for at least 5 and 6.

@bluetech
Copy link
Member

bluetech commented Jan 9, 2022

The model for the fixes needed for File+Item inheritance and path/fspath issues is pytest-pyflakes: https://github.com/asmeurer/pytest-flakes/blob/master/pytest_flakes.py

I can submit a PR for pytest-isort when I get a chance (and if someone else does feel free to ping me for review).

@The-Compiler
Copy link
Member Author

One thing I'm wondering about is if we need a better/nicer error output in pytest for this case? Then again we did't see the same kind of failure in any other projects, so I suppose it could be okay as-is.

@The-Compiler
Copy link
Member Author

Seems like nobody picked this up so far, so I guess we'll just live with this for 7.0.0. I guess that's acceptable given that it only seems to affect one plugin, at least from what @hroncok tested in Fedora.

If someone can take a look at fixing the underlying issue in pytest-isort, that'd be great though!

@nicoddemus
Copy link
Member

Opened stephrdev/pytest-isort#40 for this. 👍

@stephrdev
Copy link

Perfect, will look into this tonight.

@nicoddemus
Copy link
Member

@stephrdev if you can go to the page earlier than that to at least let the CI run, it would be great. 👍

image

@nicoddemus
Copy link
Member

Fixed in stephrdev/pytest-isort#40

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: help wanted developers would like help from experts on this topic type: backward compatibility might present some backward compatibility issues which should be carefully noted in the changelog
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants