1"""
2Entrypoint for testing from the top-level namespace.
3"""
4from __future__ import annotations
5
6import os
7import sys
8
9from pandas.compat._optional import import_optional_dependency
10
11PKG = os.path.dirname(os.path.dirname(__file__))
12
13
14def test(extra_args: list[str] | None = None, run_doctests: bool = False) -> None:
15 """
16 Run the pandas test suite using pytest.
17
18 By default, runs with the marks -m "not slow and not network and not db"
19
20 Parameters
21 ----------
22 extra_args : list[str], default None
23 Extra marks to run the tests.
24 run_doctests : bool, default False
25 Whether to only run the Python and Cython doctests. If you would like to run
26 both doctests/regular tests, just append "--doctest-modules"/"--doctest-cython"
27 to extra_args.
28
29 Examples
30 --------
31 >>> pd.test() # doctest: +SKIP
32 running: pytest...
33 """
34 pytest = import_optional_dependency("pytest")
35 import_optional_dependency("hypothesis")
36 cmd = ["-m not slow and not network and not db"]
37 if extra_args:
38 if not isinstance(extra_args, list):
39 extra_args = [extra_args]
40 cmd = extra_args
41 if run_doctests:
42 cmd = [
43 "--doctest-modules",
44 "--doctest-cython",
45 f"--ignore={os.path.join(PKG, 'tests')}",
46 ]
47 cmd += [PKG]
48 joined = " ".join(cmd)
49 print(f"running: pytest {joined}")
50 sys.exit(pytest.main(cmd))
51
52
53__all__ = ["test"]