xflr6 / graphviz

Simple Python interface for Graphviz
https://graphviz.readthedocs.io
MIT License
1.65k stars 213 forks source link

[0.19] test suite fails with: 'Namespace' object has no attribute '--only-exe' #152

Closed DimStar77 closed 2 years ago

DimStar77 commented 2 years ago

somehow on my system (openSUSE Tumbleweed, i.e. rolling distro), the test suite of this package (version 0.19) fails with:

> python3 run-tests.py 
pytest.main([])
============================================= test session starts ==============================================
platform linux -- Python 3.8.12, pytest-6.2.5, py-1.10.0, pluggy-1.0.0
rootdir: /home/abuild/rpmbuild/BUILD/graphviz-0.19, configfile: setup.cfg, testpaths: README.rst, docs, graphviz, tests
plugins: mock-3.6.1, cov-3.0.0
collected 321 items                                                                                            
INTERNALERROR> Traceback (most recent call last):
INTERNALERROR>   File "/usr/lib/python3.8/site-packages/_pytest/config/__init__.py", line 1463, in getoption
INTERNALERROR>     val = getattr(self.option, name)
INTERNALERROR> AttributeError: 'Namespace' object has no attribute '--only-exe'
INTERNALERROR> 
INTERNALERROR> The above exception was the direct cause of the following exception:
INTERNALERROR> 
INTERNALERROR> Traceback (most recent call last):
INTERNALERROR>   File "/usr/lib/python3.8/site-packages/_pytest/main.py", line 269, in wrap_session
INTERNALERROR>     session.exitstatus = doit(config, session) or 0
INTERNALERROR>   File "/usr/lib/python3.8/site-packages/_pytest/main.py", line 322, in _main
INTERNALERROR>     config.hook.pytest_collection(session=session)
INTERNALERROR>   File "/usr/lib/python3.8/site-packages/pluggy/_hooks.py", line 265, in __call__
INTERNALERROR>     return self._hookexec(self.name, self.get_hookimpls(), kwargs, firstresult)
INTERNALERROR>   File "/usr/lib/python3.8/site-packages/pluggy/_manager.py", line 80, in _hookexec
INTERNALERROR>     return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
INTERNALERROR>   File "/usr/lib/python3.8/site-packages/pluggy/_callers.py", line 60, in _multicall
INTERNALERROR>     return outcome.get_result()
INTERNALERROR>   File "/usr/lib/python3.8/site-packages/pluggy/_result.py", line 60, in get_result
INTERNALERROR>     raise ex[1].with_traceback(ex[2])
INTERNALERROR>   File "/usr/lib/python3.8/site-packages/pluggy/_callers.py", line 39, in _multicall
INTERNALERROR>     res = hook_impl.function(*args)
INTERNALERROR>   File "/usr/lib/python3.8/site-packages/_pytest/main.py", line 333, in pytest_collection
INTERNALERROR>     session.perform_collect()
INTERNALERROR>   File "/usr/lib/python3.8/site-packages/_pytest/main.py", line 637, in perform_collect
INTERNALERROR>     hook.pytest_collection_modifyitems(
INTERNALERROR>   File "/usr/lib/python3.8/site-packages/pluggy/_hooks.py", line 265, in __call__
INTERNALERROR>     return self._hookexec(self.name, self.get_hookimpls(), kwargs, firstresult)
INTERNALERROR>   File "/usr/lib/python3.8/site-packages/pluggy/_manager.py", line 80, in _hookexec
INTERNALERROR>     return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
INTERNALERROR>   File "/usr/lib/python3.8/site-packages/pluggy/_callers.py", line 60, in _multicall
INTERNALERROR>     return outcome.get_result()
INTERNALERROR>   File "/usr/lib/python3.8/site-packages/pluggy/_result.py", line 60, in get_result
INTERNALERROR>     raise ex[1].with_traceback(ex[2])
INTERNALERROR>   File "/usr/lib/python3.8/site-packages/pluggy/_callers.py", line 39, in _multicall
INTERNALERROR>     res = hook_impl.function(*args)
INTERNALERROR>   File "/home/abuild/rpmbuild/BUILD/graphviz-0.19/tests/conftest.py", line 16, in pytest_collection_modifyitems
INTERNALERROR>     if config.getoption(ONLY_EXE) or config.getoption(SKIP_EXE):
INTERNALERROR>   File "/usr/lib/python3.8/site-packages/_pytest/config/__init__.py", line 1474, in getoption
INTERNALERROR>     raise ValueError(f"no option named {name!r}") from e
INTERNALERROR> ValueError: no option named '--only-exe'

Used pytest 6.2.5

xflr6 commented 2 years ago

Thanks. Can you re-try with the master master branch if d43eea79cb9be87424014fd37201319d4eadd9de fixes this?

xflr6 commented 2 years ago

I think this should be fixed in new 0.19.1 release: closing -- please re-open if this still comes up.

DimStar77 commented 2 years ago

Not sure if you'd rather want a different issue, but the test suite still fails, now with a different error though:

________________________________ ERROR collecting graphviz/backend/rendering.py ________________________________
/usr/lib64/python3.8/doctest.py:939: in find
    self._find(tests, obj, name, module, source_lines, globs, {})
/usr/lib/python3.8/site-packages/_pytest/doctest.py:522: in _find
    doctest.DocTestFinder._find(  # type: ignore
/usr/lib64/python3.8/doctest.py:1001: in _find
    self._find(tests, val, valname, module, source_lines,
/usr/lib/python3.8/site-packages/_pytest/doctest.py:522: in _find
    doctest.DocTestFinder._find(  # type: ignore
/usr/lib64/python3.8/doctest.py:989: in _find
    test = self._get_test(obj, name, module, globs, source_lines)
/usr/lib64/python3.8/doctest.py:1073: in _get_test
    return self._parser.get_doctest(docstring, globs, name,
/usr/lib64/python3.8/doctest.py:675: in get_doctest
    return DocTest(self.get_examples(string, name), globs,
/usr/lib64/python3.8/doctest.py:689: in get_examples
    return [x for x in self.parse(string, name)
/usr/lib64/python3.8/doctest.py:651: in parse
    self._parse_example(m, name, lineno)
/usr/lib64/python3.8/doctest.py:732: in _parse_example
    options = self._find_options(source, name, lineno)
/usr/lib64/python3.8/doctest.py:761: in _find_options
    raise ValueError('line %r of the doctest for %s '
E   ValueError: line 12 of the doctest for graphviz.backend.rendering.infer_format has an invalid option: '+NO_EXE'
xflr6 commented 2 years ago

Thanks. Let's keep it here for now.

graphviz.backend.rendering.infer_format has an invalid option: '+NO_EXE'

Can you maybe provide more information how exactly you are running the tests?

The directory from which the tests are started (project root) should contain conftest.py.

run-tests.py defines the doctest option that this complains about.

DimStar77 commented 2 years ago

Sure - I'm building packages for openSUSE Tumbleweed, currently in my test branch found at https://build.opensuse.org/package/show/home:dimstar:Factory/python-graphviz

A full build log (incl test run) can be found at https://build.opensuse.org/package/live_build_log/home:dimstar:Factory/python-graphviz/openSUSE_Factory/x86_64

I might have found something - our tooling by default runs 'pytest' directly, which does not take tun-tests.py into account; running python3 run-tests.py makes the tests pass, so I'd say 'all is good'; sorry for the noise

xflr6 commented 2 years ago

our tooling by default runs 'pytest' directly, which does not take tun-tests.py into account

Thanks. +1 that this should be it (see spec file).

For context: We moved the pytest command line options to conftest.py in the project root so we do not need to repeat that inside docs and graphviz for running specific doctests only (there is still some repetition to make build-docs.py -b doctest work in docs/conf.py). It has the drawback that pytest adds the project root to sys.path so that e.g. on tox it does not test the installed version (some use the src layout for this reason). I still want to experiment a bit to see if there is a better solution.

Now that we got rid of docs/conftest.py and graphviz/conftest.py I think we can also move the doctest flag handling from run-test.py over to conftest.py in the project root which should fix running pytest directly instead of run-test.py.

Can you check if this branch would work with your setup?

DimStar77 commented 2 years ago

Can you check if this branch would work with your setup?

With this branch, I can use our default %pytest macro and it passes.

For me, both options are valid: adding that patch (if you consider adding this to the tree) or running run-tests.py; the spec file can easily accommodate to that too (just took me a bit to figure out that 'just' running pytest would not work for this package; no biggie)

xflr6 commented 2 years ago

Thanks. +1 that run-tests.py is the recommended/official way to run the tests, but if we can fix bare pytest running with 961dbdd607399e264a752a73df874f686538d949 for the next version then SG to do that, merged to master.