Repository navigation
Don't crash if an item has no _fixtureinfo attribute - #2789
Conversation
There was a problem hiding this comment.
Thanks @obestwalter, that's definitely a good start!
We should add a regression test for it though. I think you can add a new test in testing/python/show_fixtures_per_test.py that contains a docstring with a doctest and a text file, I suggest:
def test_doctest_items(testdir):
testdir.makepyfile('''
def foo():
"""
>>> 1 + 1
2
"""
''')
testdir.maketxtfile('''
>>> 1 + 1
2
''')
result = testdir.runpytest("--fixtures-per-test", "--doctest-modules", "--doctest-glob=*.txt", "-v")
assert result.ret == 0
result.stdout.fnmatch_lines([
'*collected 2 items*',
])This fails for me with the same error you got originally.
Also, please add a new towncrier entry, I suggest 2788.bugfix:
Fix crash when using ``--fixtures-per-test`` in directories with doc test items (docstrings or text files).
| tw.line(' no docstring available', red=True) | ||
|
|
||
| def write_item(item): | ||
| name2fixturedefs = item._fixtureinfo.name2fixturedefs |
There was a problem hiding this comment.
This is just me and a question of preference, but I try to narrow down my try/except blocks as much as possible, so I would write instead:
try:
name2fixturedefs = item._fixtureinfo.name2fixturedefs
except AttributeError:
return
if not name2fixturedefs:
returnBut really it is up to you. 👍
There was a problem hiding this comment.
good point. will do that.
|
Thanks, will fix it up properly tomorrow :) |
nicoddemus
left a comment
There was a problem hiding this comment.
Awesome, thanks! I like the small refactorings you did there. 👍
* doxtests don't seem to have this attribute, so nothing will be written in that case. * tried to be a good boy scout and tidied up surrounding code a bit (comments, shadowed/unused names, removed random new lines, naming things)
|
Thanks. Bit of a mess up now though: I want to learn to have a cleaner commit history so I squashed the changes, but this has closed this PR. Need to learn how to do this properly ... |
|
ah just reopening contains the single commit then ... phew |
Did you do it locally? I do it frequently and it doesn't need to close the PR. Here's how I usually do it: |
|
Yes, locally: I did a soft reset to the last commit before my changes, stashed the changes, then did a hard reset to that commit, then a force push and then unstashed, committed and pushed the changes again ... that was the first thing I could think of how to do this ... Until now I have only really worked on projects where nobody cares much about git history cleanliness, so I never bothered and stacked up commit on commit - working on tox now though I start to care so I have to up my game there :) Will do some reading about how to do this without upsetting the github side of things. |
|
o.k. the way you did it looks much easier anyway - so: |
OK, this is what closed the PR then: this ended up pushing a branch with no changes compared to master. A little weird that this closes the existing PR, but at least it is consistent given that you can't create a PR without any changes compared to the target branch. |
|
Makes sense. |
|
Unless somebody wants more time to review this I will merge this later today! 👍 |
|
Thanks @obestwalter! |
fixes #2788
Simplest possible way of making that error go away. I have obviously no idea what I am doing though.