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

Fix handling of duplicate args with regard to Python packages #4319

Merged

Conversation

blueyed
Copy link
Contributor

@blueyed blueyed commented Nov 6, 2018

Packages are collected twice.

Fails with:

E       Failed: nomatch: 'collected 2 items'
E           and: '==================================================================================== test session starts ====================================================================================='
E           and: 'platform linux -- Python 3.6.6, pytest-3.10.1.dev18+g01c8fab1, py-1.7.0, pluggy-0.8.0'
E           and: "hypothesis profile 'default' -> database=DirectoryBasedExampleDatabase('…/Vcs/pytest/.hypothesis/examples')"
E           and: 'rootdir: /tmp/pytest-of-user/pytest-683/test_collect_init_tests0, inifile: pytest.ini'
E           and: 'plugins: testmon-0.9.13, hypothesis-3.71.10'
E       exact match: 'collected 2 items'
E       fnmatch: '<Package *'
E          with: "<Package '/tmp/pytest-of-user/pytest-683/test_collect_init_tests0/tests'>"
E       nomatch: "  <Module '__init__.py'>"
E           and: "  <Package '/tmp/pytest-of-user/pytest-683/test_collect_init_tests0/tests'>"
E           and: "    <Module '__init__.py'>"
E           and: "      <Function 'test_init'>"
E           and: "    <Module 'test_foo.py'>"
E           and: "      <Function 'test_foo'>"
E           and: ''
E           and: '================================================================================ no tests ran in 0.02 seconds ================================================================================'
E           and: ''
E       remains unmatched: "  <Module '__init__.py'>"

…/Vcs/pytest/testing/test_collection.py:970: Failed

Found while looking into #4310.

@blueyed blueyed force-pushed the harden-test_collect_init_tests branch from 0d7525e to 3c595f0 Compare November 6, 2018 19:07
@blueyed
Copy link
Contributor Author

blueyed commented Nov 6, 2018

Found a fix.
I still think collection needs some cleanup (#4310 (comment)).

This was introduced with e041823, but before it would only collect 1 item:

collected 1 item
<Package '/tmp/pytest-of-daniel/pytest-760/test_collect_init_tests0/tests'>
  <Module 'test_foo.py'>
    <Function 'test_foo'>

@blueyed
Copy link
Contributor Author

blueyed commented Nov 7, 2018

Sorry, it does not fix #4310 yet.

@blueyed blueyed force-pushed the harden-test_collect_init_tests branch from 9a450d7 to fa35f65 Compare November 7, 2018 09:06
@blueyed blueyed changed the title collection: fix self-referencing Package entry Fix handling of duplicate args with regard to Python packages Nov 7, 2018
@blueyed
Copy link
Contributor Author

blueyed commented Nov 7, 2018

Reverted _collect_seen_pkgdirs which was meant to collect packages first, but test_generate_tests_only_done_in_subdir failed with it.
This now documents the current behavior, where we get the same package twice for example, but it should not have duplicates anymore.

@nicoddemus
Copy link
Member

Definitely agree that we need to improve collection tests coverage and refactor the code itself.

@RonnyPfannschmidt RonnyPfannschmidt merged commit 64762d2 into pytest-dev:master Nov 7, 2018
@blueyed
Copy link
Contributor Author

blueyed commented Nov 7, 2018

Ahem.. this was not really ready for merging - there is e.g. a TODO commit in there.. :/

Sorry for not marking it WIP, but it is clearly visible from the commit history..

@blueyed blueyed deleted the harden-test_collect_init_tests branch November 7, 2018 20:50
@RonnyPfannschmidt
Copy link
Member

ouch my bad, i did read the commit lines but i completely missed the TODO:

@blueyed
Copy link
Contributor Author

blueyed commented Nov 7, 2018

..and the XXX.

Typically I would like to get fixes / refactors like this into a single commit (not even the annoying merge commits), i.e. squash-merge them when ready.

It is really frustrating to go back and forth with all the single commits that have been done in this area already for the package-scoped fixtures.. :(

@blueyed
Copy link
Contributor Author

blueyed commented Nov 7, 2018

..and everything in this regard seems to be ad-hoc, instead of discussing/reviewing stuff carefully.

]
)
result = testdir.runpytest("./tests/test_foo.py", "--collect-only")
result.stdout.fnmatch_lines(["*<Module 'test_foo.py'>", "*<Function 'test_foo'>"])
result.stdout.fnmatch_lines(
["<Package */tests'>", " <Module 'test_foo.py'>", " <Function 'test_foo'>"]
Copy link
Contributor Author

Choose a reason for hiding this comment

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

btw: can black be told to keep these as separate lines?
It is much more readable then IMHO.

Copy link
Member

Choose a reason for hiding this comment

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

@blueyed you can use # fmt: off/on blocks for those, i believe we also support multiline strings that will be split/striped

Copy link
Member

Choose a reason for hiding this comment

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

AFAIK black doesn't have many configuration options, on purpose.

@pytest-dev pytest-dev deleted a comment from codecov bot Oct 28, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants