-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Description
Hey there -
very difficult to reproduce this consistently, as the behavior changes arbitrarily. see my comment below for reproducer
The bad behavior looks like this:
[classic@framework sqlalchemy:try_pytest_9]$ .nox/tests-py313-sqlite-cext-backendonly/bin/python -m pytest -v --db sqlite --write-idents ident.txt -s
ERROR: usage: __main__.py [options] [file_or_dir] [file_or_dir] [...]
__main__.py: error: unrecognized arguments: --db --write-idents
inifile: /home/classic/dev/sqlalchemy/pyproject.toml
rootdir: /home/classic/dev/sqlalchemy
Where the file https://github.com/sqlalchemy/sqlalchemy/blob/main/test/conftest.py is not being loaded before pytest parses the arguments. If I make random changes to the command, like the exact filename in my custom --write-idents option, then it works. or maybe it fails after a few runs. the behavior seems to be non-deterministic.
If I start pytest and specify test on the CLI as the folder to look in, then it will work every time, which makes sense OK:
[classic@framework sqlalchemy:try_pytest_9]$ .nox/tests-py313-sqlite-cext-backendonly/bin/python -m pytest -v test/ --db sqlite --write-idents ident.txt -s
but if I use the python_files option to do the same thing, that does not work:
[tool.pytest.ini_options]
addopts = "--tb native -v -r sfxX --maxfail=250 -p warnings -p logging --strict-markers"
# will still fail to read test/conftest.py at startup, non-deterministically
testpaths = ["test"]
python_files = "test_*.py"
reproducer (updated):
git clone https://github.com/sqlalchemy/sqlalchemy.git
cd sqlalchemy/
virtualenv .venv
.venv/bin/pip install pytest>=9 pytest-xdist typing_extensions
touch idents.txt
.venv/bin/python -m pytest --db sqlite --write-idents idents.txt
the --db and --write-idents options are custom arguments. it seems to complain more often when --write-idents is part of the CLI.
but mostly if we can look at what has changed about how conftest.py is loaded, mine is not getting loaded consistently. Here's part of a sample Jenkins run showing the problem
10:08:29 nox > Will store junit xml in junit-mssql-cext-backendonly.xml
10:08:29 nox > python -m pytest -n2 --max-worker-restart=5 --dburi 'mssql+pyodbc://scott:tiger^5HHH@mssql2022:1433/test?driver=ODBC+Driver+18+for+SQL+Server&trustservercertificate=yes&Encrypt=Optional' --dbdriver pyodbc --dbdriver pymssql --dbdriver aioodbc -m backend --write-idents db_idents.txt --junitxml junit-mssql-cext-backendonly.xml
10:08:32 =========================== sqlalchemy installation ============================
10:08:32 SQLAlchemy 2.1.0b1 (no user site)
10:08:32 Path: /home/jenkins/workspace/sqlalchemy/gerrit_21@3/py313-mssql-cext-backendonly/sqlalchemy/sqlalchemy/.nox/tests-py313-mssql-cext-backendonly/lib/python3.13/site-packages/sqlalchemy/__init__.py
10:08:32 compiled extension enabled, e.g. /home/jenkins/workspace/sqlalchemy/gerrit_21@3/py313-mssql-cext-backendonly/sqlalchemy/sqlalchemy/.nox/tests-py313-mssql-cext-backendonly/lib/python3.13/site-packages/sqlalchemy/engine/_util_cy.cpython-313-x86_64-linux-gnu.so
10:08:32 ============================= test session starts ==============================
10:08:32 platform linux -- Python 3.13.7, pytest-9.0.0, pluggy-1.6.0 -- /home/jenkins/workspace/sqlalchemy/gerrit_21@3/py313-mssql-cext-backendonly/sqlalchemy/sqlalchemy/.nox/tests-py313-mssql-cext-backendonly/bin/python
10:08:32 cachedir: .pytest_cache
10:08:32 rootdir: /home/jenkins/workspace/sqlalchemy/gerrit_21@3/py313-mssql-cext-backendonly/sqlalchemy/sqlalchemy
10:08:32 configfile: pyproject.toml
10:08:32 plugins: xdist-3.8.0
10:08:32 created: 2/2 workers
10:08:32 [gw1] node down: Traceback (most recent call last):
10:08:32 File "/home/jenkins/workspace/sqlalchemy/gerrit_21@3/py313-mssql-cext-backendonly/sqlalchemy/sqlalchemy/.nox/tests-py313-mssql-cext-backendonly/lib/python3.13/site-packages/execnet/gateway_base.py", line 1291, in executetask
10:08:32 exec(co, loc)
10:08:32 ~~~~^^^^^^^^^
10:08:32 File "/home/jenkins/workspace/sqlalchemy/gerrit_21@3/py313-mssql-cext-backendonly/sqlalchemy/sqlalchemy/.nox/tests-py313-mssql-cext-backendonly/lib/python3.13/site-packages/xdist/remote.py", line 420, in <module>
10:08:32 config = _prepareconfig(args, None)
10:08:32 File "/home/jenkins/workspace/sqlalchemy/gerrit_21@3/py313-mssql-cext-backendonly/sqlalchemy/sqlalchemy/.nox/tests-py313-mssql-cext-backendonly/lib/python3.13/site-packages/_pytest/config/__init__.py", line 358, in _prepareconfig
10:08:32 config: Config = pluginmanager.hook.pytest_cmdline_parse(
10:08:32 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
10:08:32 pluginmanager=pluginmanager, args=args
10:08:32 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
10:08:32 )
10:08:32 ^
10:08:32 File "/home/jenkins/workspace/sqlalchemy/gerrit_21@3/py313-mssql-cext-backendonly/sqlalchemy/sqlalchemy/.nox/tests-py313-mssql-cext-backendonly/lib/python3.13/site-packages/pluggy/_hooks.py", line 512, in __call__
10:08:32 return self._hookexec(self.name, self._hookimpls.copy(), kwargs, firstresult)
10:08:32 ~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
10:08:32 File "/home/jenkins/workspace/sqlalchemy/gerrit_21@3/py313-mssql-cext-backendonly/sqlalchemy/sqlalchemy/.nox/tests-py313-mssql-cext-backendonly/lib/python3.13/site-packages/pluggy/_manager.py", line 120, in _hookexec
10:08:32 return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
10:08:32 ~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
10:08:32 File "/home/jenkins/workspace/sqlalchemy/gerrit_21@3/py313-mssql-cext-backendonly/sqlalchemy/sqlalchemy/.nox/tests-py313-mssql-cext-backendonly/lib/python3.13/site-packages/pluggy/_callers.py", line 167, in _multicall
10:08:32 raise exception
10:08:32 File "/home/jenkins/workspace/sqlalchemy/gerrit_21@3/py313-mssql-cext-backendonly/sqlalchemy/sqlalchemy/.nox/tests-py313-mssql-cext-backendonly/lib/python3.13/site-packages/pluggy/_callers.py", line 139, in _multicall
10:08:32 teardown.throw(exception)
10:08:32 ~~~~~~~~~~~~~~^^^^^^^^^^^
10:08:32 File "/home/jenkins/workspace/sqlalchemy/gerrit_21@3/py313-mssql-cext-backendonly/sqlalchemy/sqlalchemy/.nox/tests-py313-mssql-cext-backendonly/lib/python3.13/site-packages/_pytest/helpconfig.py", line 124, in pytest_cmdline_parse
10:08:32 config = yield
10:08:32 ^^^^^
10:08:32 File "/home/jenkins/workspace/sqlalchemy/gerrit_21@3/py313-mssql-cext-backendonly/sqlalchemy/sqlalchemy/.nox/tests-py313-mssql-cext-backendonly/lib/python3.13/site-packages/pluggy/_callers.py", line 121, in _multicall
10:08:32 res = hook_impl.function(*args)
10:08:32 File "/home/jenkins/workspace/sqlalchemy/gerrit_21@3/py313-mssql-cext-backendonly/sqlalchemy/sqlalchemy/.nox/tests-py313-mssql-cext-backendonly/lib/python3.13/site-packages/_pytest/config/__init__.py", line 1155, in pytest_cmdline_parse
10:08:32 self.parse(args)
10:08:32 ~~~~~~~~~~^^^^^^
10:08:32 File "/home/jenkins/workspace/sqlalchemy/gerrit_21@3/py313-mssql-cext-backendonly/sqlalchemy/sqlalchemy/.nox/tests-py313-mssql-cext-backendonly/lib/python3.13/site-packages/_pytest/config/__init__.py", line 1540, in parse
10:08:32 self._parser.parse(args, namespace=self.option)
10:08:32 ~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
10:08:32 File "/home/jenkins/workspace/sqlalchemy/gerrit_21@3/py313-mssql-cext-backendonly/sqlalchemy/sqlalchemy/.nox/tests-py313-mssql-cext-backendonly/lib/python3.13/site-packages/_pytest/config/argparsing.py", line 145, in parse
10:08:32 return self.optparser.parse_intermixed_args(strargs, namespace=namespace)
10:08:32 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
10:08:32 File "/opt/python3.13/lib/python3.13/argparse.py", line 2465, in parse_intermixed_args
10:08:32 self.error(msg)
10:08:32 ~~~~~~~~~~^^^^^
10:08:32 File "/home/jenkins/workspace/sqlalchemy/gerrit_21@3/py313-mssql-cext-backendonly/sqlalchemy/sqlalchemy/.nox/tests-py313-mssql-cext-backendonly/lib/python3.13/site-packages/_pytest/config/argparsing.py", line 476, in error
10:08:32 raise UsageError(self.format_usage() + msg)
10:08:32 pytest.UsageError: usage: -c [options] [file_or_dir] [file_or_dir] [...]
10:08:32 -c: error: unrecognized arguments: --dburi --dbdriver --dbdriver --dbdriver --write-idents
10:08:32 inifile: /home/jenkins/workspace/sqlalchemy/gerrit_21@3/py313-mssql-cext-backendonly/sqlalchemy/sqlalchemy/pyproject.toml
10:08:32 rootdir: /home/jenkins/workspace/sqlalchemy/gerrit_21@3/py313-mssql-cext-backendonly/sqlalchemy/sqlalchemy
10:08:32
10:08:32
10:08:32 replacing crashed worker gw1
10:08:32 [gw2] node down: Traceback (most recent call last):
10:08:32 File "/home/jenkins/workspace/sqlalchemy/gerrit_21@3/py313-mssql-cext-backendonly/sqlalchemy/sqlalchemy/.nox/tests-py313-mssql-cext-backendonly/lib/python3.13/site-packages/execnet/gateway_base.py", line 1291, in executetask
10:08:32 exec(co, loc)
10:08:32 ~~~~^^^^^^^^^
10:08:32 File "/home/jenkins/workspace/sqlalchemy/gerrit_21@3/py313-mssql-cext-backendonly/sqlalchemy/sqlalchemy/.nox/tests-py313-mssql-cext-backendonly/lib/python3.13/site-packages/xdist/remote.py", line 420, in <module>
10:08:32 config = _prepareconfig(args, None)
10:08:32 File "/home/jenkins/workspace/sqlalchemy/gerrit_21@3/py313-mssql-cext-backendonly/sqlalchemy/sqlalchemy/.nox/tests-py313-mssql-cext-backendonly/lib/python3.13/site-packages/_pytest/config/__init__.py", line 358, in _prepareconfig
10:08:32 config: Config = pluginmanager.hook.pytest_cmdline_parse(
10:08:32 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
10:08:32 pluginmanager=pluginmanager, args=args
10:08:32 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
10:08:32 )
10:08:32 ^
10:08:32 File "/home/jenkins/workspace/sqlalchemy/gerrit_21@3/py313-mssql-cext-backendonly/sqlalchemy/sqlalchemy/.nox/tests-py313-mssql-cext-backendonly/lib/python3.13/site-packages/pluggy/_hooks.py", line 512, in __call__
10:08:32 return self._hookexec(self.name, self._hookimpls.copy(), kwargs, firstresult)
10:08:32 ~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
10:08:32 File "/home/jenkins/workspace/sqlalchemy/gerrit_21@3/py313-mssql-cext-backendonly/sqlalchemy/sqlalchemy/.nox/tests-py313-mssql-cext-backendonly/lib/python3.13/site-packages/pluggy/_manager.py", line 120, in _hookexec
10:08:32 return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
10:08:32 ~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
10:08:32 File "/home/jenkins/workspace/sqlalchemy/gerrit_21@3/py313-mssql-cext-backendonly/sqlalchemy/sqlalchemy/.nox/tests-py313-mssql-cext-backendonly/lib/python3.13/site-packages/pluggy/_callers.py", line 167, in _multicall
10:08:32 raise exception
10:08:32 File "/home/jenkins/workspace/sqlalchemy/gerrit_21@3/py313-mssql-cext-backendonly/sqlalchemy/sqlalchemy/.nox/tests-py313-mssql-cext-backendonly/lib/python3.13/site-packages/pluggy/_callers.py", line 139, in _multicall
10:08:32 teardown.throw(exception)
10:08:32 ~~~~~~~~~~~~~~^^^^^^^^^^^
10:08:32 File "/home/jenkins/workspace/sqlalchemy/gerrit_21@3/py313-mssql-cext-backendonly/sqlalchemy/sqlalchemy/.nox/tests-py313-mssql-cext-backendonly/lib/python3.13/site-packages/_pytest/helpconfig.py", line 124, in pytest_cmdline_parse
10:08:32 config = yield
10:08:32 ^^^^^
10:08:32 File "/home/jenkins/workspace/sqlalchemy/gerrit_21@3/py313-mssql-cext-backendonly/sqlalchemy/sqlalchemy/.nox/tests-py313-mssql-cext-backendonly/lib/python3.13/site-packages/pluggy/_callers.py", line 121, in _multicall
10:08:32 res = hook_impl.function(*args)
10:08:32 File "/home/jenkins/workspace/sqlalchemy/gerrit_21@3/py313-mssql-cext-backendonly/sqlalchemy/sqlalchemy/.nox/tests-py313-mssql-cext-backendonly/lib/python3.13/site-packages/_pytest/config/__init__.py", line 1155, in pytest_cmdline_parse
10:08:32 self.parse(args)
10:08:32 ~~~~~~~~~~^^^^^^
10:08:32 File "/home/jenkins/workspace/sqlalchemy/gerrit_21@3/py313-mssql-cext-backendonly/sqlalchemy/sqlalchemy/.nox/tests-py313-mssql-cext-backendonly/lib/python3.13/site-packages/_pytest/config/__init__.py", line 1540, in parse
10:08:32 self._parser.parse(args, namespace=self.option)
10:08:32 ~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
10:08:32 File "/home/jenkins/workspace/sqlalchemy/gerrit_21@3/py313-mssql-cext-backendonly/sqlalchemy/sqlalchemy/.nox/tests-py313-mssql-cext-backendonly/lib/python3.13/site-packages/_pytest/config/argparsing.py", line 145, in parse
10:08:32 return self.optparser.parse_intermixed_args(strargs, namespace=namespace)
10:08:32 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
10:08:32 File "/opt/python3.13/lib/python3.13/argparse.py", line 2465, in parse_intermixed_args
10:08:32 self.error(msg)
10:08:32 ~~~~~~~~~~^^^^^
10:08:32 File "/home/jenkins/workspace/sqlalchemy/gerrit_21@3/py313-mssql-cext-backendonly/sqlalchemy/sqlalchemy/.nox/tests-py313-mssql-cext-backendonly/lib/python3.13/site-packages/_pytest/config/argparsing.py", line 476, in error
10:08:32 raise UsageError(self.format_usage() + msg)
10:08:32 pytest.UsageError: usage: -c [options] [file_or_dir] [file_or_dir] [...]
10:08:32 -c: error: unrecognized arguments: --dburi --dbdriver --dbdriver --dbdriver --write-idents
10:08:32 inifile: /home/jenkins/workspace/sqlalchemy/gerrit_21@3/py313-mssql-cext-backendonly/sqlalchemy/sqlalchemy/pyproject.toml
10:08:32 rootdir: /home/jenkins/workspace/sqlalchemy/gerrit_21@3/py313-mssql-cext-backendonly/sqlalchemy/sqlalchemy
10:08:33
10:08:33