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

BUG: Fix use with doctest + fixtures #41

Merged
merged 3 commits into from Sep 18, 2020
Merged

Conversation

larsoner
Copy link
Contributor

@larsoner larsoner commented Sep 11, 2020

Fixes #42

On master using --doctest-modules with fixtures leads to:

pytest_harvest/results_session.py:167: in get_session_synthesis_dct
    param_dct = get_pytest_params(item)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

item = <DoctestItem pytest_harvest.plugin.dummy>

    def get_pytest_params(item):
        """ Returns a dictionary containing a pytest session item's parameters """
    
        if isinstance(item, _MinimalItem):
            # Our special _MinimalItem object - when xdist is used and worker states have been saved + restored
            return item.get_pytest_params()
        else:
            param_dct = OrderedDict()
>           for param_name in item.fixturenames:  # note: item.funcargnames gives the exact same list
E           AttributeError: 'DoctestItem' object has no attribute 'fixturenames'

and also

pytest_harvest/results_session.py:234: in <genexpr>
    filtered_items = tuple(item for item in session.items if _pytest_item_matches_filter(item, filterset))
pytest_harvest/results_session.py:327: in _pytest_item_matches_filter
    elif any(item_obj.__module__ == f for f in filterset):
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

.0 = <set_iterator object at 0x7ffe00770140>

>   elif any(item_obj.__module__ == f for f in filterset):
E   AttributeError: 'NoneType' object has no attribute '__module__'
  1. Added test that fails on master but passes here, along with dummy doctestable function
  2. Adjusted META test count
  3. Fixed code by adding a conditional that avoids trying to get param names from DoctestItem
  4. Fixed code by adding a conditional for the item_obj is None case
  5. Added pytest_harvest/_version.py to .gitignore (I assume this is useful?)
  6. Removed some trailing whitespace (more PEP8-y; my editor did it automatically; can revert if preferred)

FWIW locally not all tests pass actually, but the same set that fail on this PR also fail on master.

@codecov-commenter
Copy link

codecov-commenter commented Sep 11, 2020

Codecov Report

Merging #41 into master will decrease coverage by 0.18%.
The diff coverage is 66.66%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master      #41      +/-   ##
==========================================
- Coverage   88.63%   88.45%   -0.19%     
==========================================
  Files          31       31              
  Lines        1065     1074       +9     
==========================================
+ Hits          944      950       +6     
- Misses        121      124       +3     
Impacted Files Coverage Δ
pytest_harvest/plugin.py 62.12% <50.00%> (-0.19%) ⬇️
pytest_harvest/results_session.py 82.32% <60.00%> (-0.58%) ⬇️
...test_harvest/tests_raw/test_get_session_results.py 96.21% <100.00%> (+0.05%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 00a713c...0a90b0a. Read the comment docs.

@smarie
Copy link
Owner

smarie commented Sep 14, 2020

Thanks @larsoner ! I'll have a look tomorrow

Comment on lines 503 to 511
def doctestable():
"""Do nothing, but have a doctest.

Examples
--------
>>> 1 + 1
2
"""
return
Copy link
Owner

@smarie smarie Sep 15, 2020

Choose a reason for hiding this comment

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

Cant we have this doctest somewhere in the tests/ folder rather ? I'm a bit reluctant to leave it in the "main" part. Will it execute as a doctest if it is a dedicated test_xxx.py file ? I guess so

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't know if --doctests works for things in tests/, but I'll give it a shot

Copy link
Owner

Choose a reason for hiding this comment

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

ok. If it ends up being overly complex to move this to tests/, another option is simply to leave it here, but to add an underscore to the name to make it private (if doctest is happy with it).

@@ -210,6 +210,13 @@ def test_synthesis_contains_everything(request):
assert len(missing) == 0


# For some reason, adding a monkeypatch will cause an extra failure for
# DoctestItem, possibly because it's a setup/teardown
def test_deal_with_doctest(dummy):
Copy link
Owner

Choose a reason for hiding this comment

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

Can you please extend your comment by explaining what is the dummy fixture here ? Maybe it is just a fixture provided by the monkeypatch plugin but I did not find any reference to it..

@smarie
Copy link
Owner

smarie commented Sep 15, 2020

Thanks @larsoner ! Looks very good to me, I made a few comments that are mostly nitpicks really, just for the sake of making maintenance a bit easier on the long run.

All tests pass ok in Travis so I'll be able to merge when you'll have made the updates.
(the only failure that I see is in the "raw" tests, and is intended - it is then collected by the META test runner and expected to fail)

@larsoner
Copy link
Contributor Author

@smarie comments addressed

setup.py Outdated Show resolved Hide resolved
@smarie smarie merged commit 0a90b0a into smarie:master Sep 18, 2020
@larsoner
Copy link
Contributor Author

There is a wall of red here :)

https://travis-ci.org/github/smarie/python-pytest-harvest/builds/727704884

Let me know if you want my help fixing it

@smarie
Copy link
Owner

smarie commented Sep 20, 2020

Hi @larsoner I merged manually and fixed the meta-tester, everything is fine now and 1.9.3 is available.

There were 2 issues

  • first pytest starting from version 6 changed the order in which the parameters are returned by the internal API I was using
  • the meta-tests running sandboxed executions of pytest were not taking into account the configuration in setup.cfg, I had to generate a pytest.ini file to set the doctest option on.
    (see https://docs.pytest.org/en/6.0.2/writing_plugins.html#testing-plugins)

Let me know if the released version is ok for you.
And thanks again !!

@larsoner larsoner deleted the doctest branch September 21, 2020 11:05
@larsoner
Copy link
Contributor Author

@smarie yes, just pip install pytest-harvest works now!

@smarie
Copy link
Owner

smarie commented Sep 22, 2020

great, thanks for the feedback and PR @larsoner !

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.

pytest-harvest fails when some doctests exist
3 participants