You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In a few libraries I manage, I use flags to manage running just unit or regression tests using some shorthand arguments that get run via pytest --unit or pytest --regression. This collects the test files from the directories I want to run. In up to v9, I have been able to directly pass PosixPath objects to config.args, however, there seems to be a behavior change because I now have to pass a str for all the arguments.
This was a bit of a confusing change because the error in the example below isn't very obvious, and doesn't seem to be directly documented anywhere. The fix was ultimately an easy fix to just convert the paths to strings, but I'm wondering also if this was an intended change somewhere along the lines that I've missed, a missing deprecation, or bug?
frompathlibimportPathimportpytestROOT=Path(__file__).parentTEST_DATA=ROOT/"library"defpytest_addoption(parser): # noqa: D103parser.addoption(
"--unit", action="store_true", default=False, help="run tests in test/unit/."
)
parser.addoption(
"--regression",
action="store_true",
default=False,
help="run tests in test/regression/.",
)
defpytest_configure(config): # noqa: D103# Check for the optionsunit=config.getoption("--unit")
regression=config.getoption("--regression")
# Provide the appropriate directoriesunit_tests= [elforelin (ROOT/"unit").iterdir() ifel.suffix==".py"]
regression_tests= [
elforelin (ROOT/"regression").iterdir() ifel.suffix==".py"
]
# If both, run them all; if neither skip any modifications; otherwise run just the# appropriate subsetifregressionandunit:
config.args=unit_tests+regression_testselifregression:
config.args=regression_testselifunit:
config.args=unit_tests
Running pytest works just fine, but once I use either the --unit or --regression flags, I get the following output.
==================================================================================== test session starts =====================================================================================platform darwin -- Python 3.13.7, pytest-9.0.1, pluggy-1.6.0cachedir: .cacherootdir: /Users/rhammond/GitHub_Public/NREL/WOMBATconfigfile: pyproject.tomltestpaths: testsplugins: anyio-4.11.0, check-2.6.0, cov-7.0.0collected 0 items INTERNALERROR> Traceback (most recent call last):INTERNALERROR> File "/Users/rhammond/miniconda3/envs/wombat-test/lib/python3.13/site-packages/_pytest/main.py", line 318, in wrap_sessionINTERNALERROR> session.exitstatus = doit(config, session) or 0INTERNALERROR> ~~~~^^^^^^^^^^^^^^^^^INTERNALERROR> File "/Users/rhammond/miniconda3/envs/wombat-test/lib/python3.13/site-packages/_pytest/main.py", line 371, in _mainINTERNALERROR> config.hook.pytest_collection(session=session)INTERNALERROR> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^INTERNALERROR> File "/Users/rhammond/miniconda3/envs/wombat-test/lib/python3.13/site-packages/pluggy/_hooks.py", line 512, in __call__INTERNALERROR> return self._hookexec(self.name, self._hookimpls.copy(), kwargs, firstresult)INTERNALERROR> ~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^INTERNALERROR> File "/Users/rhammond/miniconda3/envs/wombat-test/lib/python3.13/site-packages/pluggy/_manager.py", line 120, in _hookexecINTERNALERROR> return self._inner_hookexec(hook_name, methods, kwargs, firstresult)INTERNALERROR> ~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^INTERNALERROR> File "/Users/rhammond/miniconda3/envs/wombat-test/lib/python3.13/site-packages/pluggy/_callers.py", line 167, in _multicallINTERNALERROR> raise exceptionINTERNALERROR> File "/Users/rhammond/miniconda3/envs/wombat-test/lib/python3.13/site-packages/pluggy/_callers.py", line 139, in _multicallINTERNALERROR> teardown.throw(exception)INTERNALERROR> ~~~~~~~~~~~~~~^^^^^^^^^^^INTERNALERROR> File "/Users/rhammond/miniconda3/envs/wombat-test/lib/python3.13/site-packages/_pytest/logging.py", line 788, in pytest_collectionINTERNALERROR> return (yield)INTERNALERROR> ^^^^^INTERNALERROR> File "/Users/rhammond/miniconda3/envs/wombat-test/lib/python3.13/site-packages/pluggy/_callers.py", line 139, in _multicallINTERNALERROR> teardown.throw(exception)INTERNALERROR> ~~~~~~~~~~~~~~^^^^^^^^^^^INTERNALERROR> File "/Users/rhammond/miniconda3/envs/wombat-test/lib/python3.13/site-packages/_pytest/warnings.py", line 98, in pytest_collectionINTERNALERROR> return (yield)INTERNALERROR> ^^^^^INTERNALERROR> File "/Users/rhammond/miniconda3/envs/wombat-test/lib/python3.13/site-packages/pluggy/_callers.py", line 139, in _multicallINTERNALERROR> teardown.throw(exception)INTERNALERROR> ~~~~~~~~~~~~~~^^^^^^^^^^^INTERNALERROR> File "/Users/rhammond/miniconda3/envs/wombat-test/lib/python3.13/site-packages/_pytest/config/__init__.py", line 1372, in pytest_collectionINTERNALERROR> return (yield)INTERNALERROR> ^^^^^INTERNALERROR> File "/Users/rhammond/miniconda3/envs/wombat-test/lib/python3.13/site-packages/pluggy/_callers.py", line 121, in _multicallINTERNALERROR> res = hook_impl.function(*args)INTERNALERROR> File "/Users/rhammond/miniconda3/envs/wombat-test/lib/python3.13/site-packages/_pytest/main.py", line 382, in pytest_collectionINTERNALERROR> session.perform_collect()INTERNALERROR> ~~~~~~~~~~~~~~~~~~~~~~~^^INTERNALERROR> File "/Users/rhammond/miniconda3/envs/wombat-test/lib/python3.13/site-packages/_pytest/main.py", line 814, in perform_collectINTERNALERROR> resolve_collection_argument(INTERNALERROR> ~~~~~~~~~~~~~~~~~~~~~~~~~~~^INTERNALERROR> self.config.invocation_params.dir,INTERNALERROR> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^INTERNALERROR> ...<3 lines>...INTERNALERROR> consider_namespace_packages=consider_namespace_packages,INTERNALERROR> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^INTERNALERROR> )INTERNALERROR> ^INTERNALERROR> File "/Users/rhammond/miniconda3/envs/wombat-test/lib/python3.13/site-packages/_pytest/main.py", line 1116, in resolve_collection_argumentINTERNALERROR> base, squacket, rest = arg.partition("[")INTERNALERROR> ^^^^^^^^^^^^^INTERNALERROR> AttributeError: 'PosixPath' object has no attribute 'partition'
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
-
In a few libraries I manage, I use flags to manage running just unit or regression tests using some shorthand arguments that get run via
pytest --unitorpytest --regression. This collects the test files from the directories I want to run. In up to v9, I have been able to directly passPosixPathobjects toconfig.args, however, there seems to be a behavior change because I now have to pass astrfor all the arguments.This was a bit of a confusing change because the error in the example below isn't very obvious, and doesn't seem to be directly documented anywhere. The fix was ultimately an easy fix to just convert the paths to strings, but I'm wondering also if this was an intended change somewhere along the lines that I've missed, a missing deprecation, or bug?
Exact code from the simplest instance of the behavior is directly pulled from https://github.com/WISDEM/WOMBAT/blob/main/tests/conftest.py.
Running
pytestworks just fine, but once I use either the--unitor--regressionflags, I get the following output.Beta Was this translation helpful? Give feedback.
All reactions