_tester.py 1.6 KB

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