Quantco / pytsql

Run mssql scripts from Python.
BSD 3-Clause "New" or "Revised" License
14 stars 3 forks source link

Spurious error during debugging: 'Namespace' object has no attribute 'backend' #46

Open windiana42 opened 1 year ago

windiana42 commented 1 year ago

This error appeared to me during debugging pytsql, then it vanished, and now it resurfaced:

Traceback (most recent call last):
  File "/home/martin/progs/pycharm-2022.2.1/plugins/python/helpers/pydev/_pydevd_bundle/pydevd_exec2.py", line 3, in Exec
    exec(exp, global_vars, local_vars)
  File "<input>", line 1, in <module>
AttributeError: 'Namespace' object has no attribute 'backend'

It could be a problem of my pycharm installation, but this is the first repo where it happens. I checked both python 3.11 and 3.10. I tested pycharm 2022.2.1 and 2022.2.4

windiana42 commented 1 year ago

tests/integration/test_multiple_statements.py:None (tests/integration/test_multiple_statements.py)
../../../progs/miniconda3/envs/pytsql/lib/python3.10/site-packages/_pytest/config/__init__.py:1540: in getoption
    val = getattr(self.option, name)
E   AttributeError: 'Namespace' object has no attribute 'backend'

The above exception was the direct cause of the following exception:
../../../progs/miniconda3/envs/pytsql/lib/python3.10/site-packages/pluggy/_hooks.py:265: in __call__
    return self._hookexec(self.name, self.get_hookimpls(), kwargs, firstresult)
../../../progs/miniconda3/envs/pytsql/lib/python3.10/site-packages/pluggy/_manager.py:80: in _hookexec
    return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
../../../progs/miniconda3/envs/pytsql/lib/python3.10/site-packages/_pytest/python.py:272: in pytest_pycollect_makeitem
    return list(collector._genfunctions(name, obj))
../../../progs/miniconda3/envs/pytsql/lib/python3.10/site-packages/_pytest/python.py:499: in _genfunctions
    self.ihook.pytest_generate_tests.call_extra(methods, dict(metafunc=metafunc))
../../../progs/miniconda3/envs/pytsql/lib/python3.10/site-packages/pluggy/_hooks.py:292: in call_extra
    return self(**kwargs)
../../../progs/miniconda3/envs/pytsql/lib/python3.10/site-packages/pluggy/_hooks.py:265: in __call__
    return self._hookexec(self.name, self.get_hookimpls(), kwargs, firstresult)
../../../progs/miniconda3/envs/pytsql/lib/python3.10/site-packages/pluggy/_manager.py:80: in _hookexec
    return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
integration/conftest.py:42: in pytest_generate_tests
    "backend", [metafunc.config.getoption("backend")], scope="module"
../../../progs/miniconda3/envs/pytsql/lib/python3.10/site-packages/_pytest/config/__init__.py:1551: in getoption
    raise ValueError(f"no option named {name!r}") from e
E   ValueError: no option named 'backend'
windiana42 commented 1 year ago

This code snippet in conftest.py seems to be related:

def pytest_generate_tests(metafunc):
    if "backend" in metafunc.fixturenames:
        metafunc.parametrize(
            "backend", [metafunc.config.getoption("backend")], scope="module"
        )
windiana42 commented 1 year ago

proposed solution will be as a commit in issue44 (#44) branch/PR:

def pytest_generate_tests(metafunc):
    if "backend" in metafunc.fixturenames:
        try:
            metafunc.parametrize(
                "backend", [metafunc.config.getoption("backend")], scope="module"
            )
        except ValueError:
            # some metafunc.config objects don't have an option "backend"
            metafunc.parametrize(
                "backend", ["default_backend"], scope="module"
            )