{
 "kind": "tool",
 "slug": "pytest",
 "path": "tools/pytest/",
 "name": "pytest",
 "maker": null,
 "density": "full",
 "crumbs": [
  [
   "Tools",
   "tools/"
  ],
  [
   "Testing",
   "tools/testing/"
  ]
 ],
 "lead": "Automatic checks for your Python code.",
 "chips": [
  {
   "label": "Testing",
   "path": "tools/testing/"
  },
  {
   "label": "PYPI"
  }
 ],
 "primary": {
  "label": "Copy install command",
  "copy": "pip install pytest"
 },
 "links": [
  {
   "label": "GitHub",
   "href": "https://github.com/pytest-dev/pytest"
  },
  {
   "label": "Website",
   "href": "https://docs.pytest.org/en/latest/"
  }
 ],
 "track": "New versions, deprecation and license changes on your dashboard",
 "verdicts": [
  {
   "key": "license",
   "label": "License",
   "value": "MIT",
   "status": "yes",
   "sub": "Use it in paid apps",
   "quote": "Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction",
   "note": "MIT allows use in paid and closed products; pytest usually stays a development tool and is not shipped.",
   "src": "https://github.com/pytest-dev/pytest/blob/main/LICENSE"
  },
  {
   "key": "maint",
   "label": "Maintained",
   "value": "Maintained",
   "status": "yes",
   "sub": "Last change Nov 24, 2026",
   "note": "Latest GitHub release Oct 27, 2026. ",
   "src": "https://github.com/pytest-dev/pytest"
  },
  {
   "key": "pop",
   "label": "Used by agents' projects",
   "value": "257 projects",
   "status": "info",
   "sub": "#6 of 122 in its category",
   "note": "Dependency in 257 public GitHub projects set up for AI coding agents that we scanned (4.1%).",
   "src": null
  },
  {
   "key": "agent",
   "label": "Agent access",
   "value": "Install only",
   "status": "info",
   "sub": null,
   "note": "Agent skills for this library in the skills catalog; community skills are written by others, read them before you install.",
   "src": null
  }
 ],
 "vfoot": "From the package registry and GitHub, checked daily; card checked Nov 11, 2026.",
 "blocks": [
  {
   "id": "overview",
   "nav": "Overview",
   "h2": "What pytest does",
   "parts": [
    {
     "t": "prose",
     "text": "pytest is a free tool that runs small checks, called tests, on your Python code and tells you which ones fail and why. Your AI assistant writes the tests next to the code, and one command shows if a change broke something. It works for a single script as well as a large app."
    },
    {
     "t": "h3",
     "text": "What people build with it"
    },
    {
     "t": "uses",
     "items": [
      {
       "title": "Check prices before each release",
       "text": "Your shop or booking app works out totals and discounts; one test table runs every coupon case, and a wrong number stops the release.",
       "idea": false
      },
      {
       "title": "Test file exports without mess",
       "text": "Code that writes receipts, reports or uploads gets a fresh empty folder for each test, so no test leaves files in your project.",
       "idea": false
      },
      {
       "title": "Test settings without real services",
       "text": "Point the app at a local address or a fake payment service for one test only; pytest puts the real setting back afterwards.",
       "idea": false
      },
      {
       "title": "Check that bad input is refused",
       "text": "Make sure a sign-up form or an import rejects wrong data with a clear error instead of saving it.",
       "idea": false
      },
      {
       "title": "Run old unittest suites as they are",
       "text": "An older project with tests in the built-in unittest style can switch to pytest without rewriting them first.",
       "idea": false
      },
      {
       "title": "Let the assistant check its own edits",
       "text": "After each change your AI assistant runs the tests and reads the failure report, which shows the values that did not match, before it says the work is done.",
       "idea": true
      }
     ]
    }
   ]
  },
  {
   "id": "popularity",
   "nav": "Popularity",
   "h2": "pytest popularity",
   "parts": [
    {
     "t": "stats",
     "items": [
      {
       "n": "81",
       "of": "/ 100",
       "l": "Gid Score, #85 overall"
      },
      {
       "n": "239M",
       "l": "downloads a week, pypi"
      },
      {
       "n": "14.7K",
       "l": "GitHub stars"
      },
      {
       "n": "257",
       "l": "agent projects use it"
      }
     ]
    },
    {
     "t": "small",
     "text": "Gid Score measures public popularity and activity, not quality.",
     "link": "How the Gid Score is calculated",
     "path": "tools/top/"
    }
   ]
  },
  {
   "id": "usage",
   "nav": "How it is used",
   "h2": "How pytest is used",
   "parts": [
    {
     "t": "list",
     "items": [
      "pytest is a dependency in 257 of the 6,258 public GitHub projects set up for AI coding agents that we scanned (15.8% of the 1,623 Python ones), #6 of 122 in testing.",
      "Counting the projects our scan samples by dependency (Solana 3,067, Ethereum and EVM 1,774, 3D and games 3,130, agent frameworks and SDKs 13,750), it appears in 1,766; those are left out of every share on this page.",
      "Projects that use it most often also use python-dotenv (55.6%), Pydantic (51.4%), Uvicorn (49.8%).",
      "It is more common in projects set up for Roo Code (10.8%) than for Gemini CLI (2.7%)."
     ]
    },
    {
     "t": "h3",
     "text": "By coding agent"
    },
    {
     "t": "rows",
     "rows": [
      {
       "l": "134 projects, 4.1%",
       "v": "Claude Code",
       "path": "agents/claude-code/"
      },
      {
       "l": "133 projects, 4.4%",
       "v": "GitHub Copilot",
       "path": "agents/github-copilot/"
      },
      {
       "l": "94 projects, 3.8%",
       "v": "Cursor",
       "path": "agents/cursor/"
      },
      {
       "l": "17 projects, 5.1%",
       "v": "OpenClaw",
       "path": "agents/openclaw/"
      },
      {
       "l": "16 projects, 5.7%",
       "v": "Devin Desktop",
       "path": "agents/devin-desktop/"
      },
      {
       "l": "14 projects, 3.0%",
       "v": "OpenAI Codex",
       "path": "agents/openai-codex/"
      },
      {
       "l": "13 projects, 2.7%",
       "v": "Gemini CLI",
       "path": "agents/gemini-cli/"
      },
      {
       "l": "12 projects, 10.8%",
       "v": "Roo Code",
       "path": "agents/roo-code/"
      }
     ]
    },
    {
     "t": "h3",
     "text": "Often used with"
    },
    {
     "t": "rows",
     "rows": [
      {
       "l": "In 55.6% of its projects",
       "v": "python-dotenv",
       "path": "tools/python-dotenv/"
      },
      {
       "l": "In 51.4% of its projects",
       "v": "Pydantic",
       "path": "tools/pydantic/"
      },
      {
       "l": "In 49.8% of its projects",
       "v": "Uvicorn",
       "path": "tools/uvicorn/"
      },
      {
       "l": "In 46.7% of its projects",
       "v": "FastAPI",
       "path": "tools/fastapi/"
      },
      {
       "l": "In 42.8% of its projects",
       "v": "Requests",
       "path": "tools/requests-py/"
      },
      {
       "l": "In 40.5% of its projects",
       "v": "NumPy",
       "path": "tools/numpy/"
      },
      {
       "l": "In 37.0% of its projects",
       "v": "PyYAML",
       "path": "tools/pyyaml/"
      },
      {
       "l": "In 33.1% of its projects",
       "v": "pandas",
       "path": "tools/pandas/"
      }
     ]
    }
   ]
  },
  {
   "id": "more",
   "nav": null,
   "spy_as": "usage",
   "h2": "More about pytest",
   "parts": [
    {
     "t": "more",
     "items": [
      {
       "title": "Funding",
       "path": "tools/funding/",
       "items": [
        "GitHub Sponsors: https://github.com/pytest-dev",
        "Tidelift: https://tidelift.com/funding/github/pypi/pytest",
        "Open Collective: https://opencollective.com/pytest",
        "thanks.dev: https://thanks.dev/u/gh/pytest-dev",
        "Own page: https://docs.pytest.org/en/stable/sponsor.html",
        "17 GitHub sponsors"
       ]
      },
      {
       "title": "More in Testing",
       "path": "tools/testing/",
       "items": [
        {
         "text": "Vitest",
         "path": "tools/vitest/"
        },
        {
         "text": "Playwright (JavaScript)",
         "path": "tools/playwright-test/"
        },
        {
         "text": "Testing Library",
         "path": "tools/testing-library/"
        },
        {
         "text": "jsdom",
         "path": "tools/jsdom/"
        },
        {
         "text": "Jest",
         "path": "tools/jest/"
        },
        {
         "text": "Happy DOM",
         "path": "tools/happy-dom/"
        },
        {
         "text": "axe-core Playwright",
         "path": "tools/axe-core-playwright/"
        },
        {
         "text": "SuperTest",
         "path": "tools/supertest/"
        }
       ]
      }
     ]
    }
   ]
  },
  {
   "id": "alternatives",
   "nav": "Alternatives",
   "h2": "Alternatives",
   "parts": [
    {
     "t": "alts",
     "items": [
      {
       "name": "pytest",
       "me": true,
       "facts": [
        "MIT",
        "Gid 81",
        "239M/wk"
       ]
      },
      {
       "name": "Vitest",
       "why": "Pick Vitest when the code to test is JavaScript or TypeScript in a Vite project, not Python.",
       "path": "tools/vitest/",
       "facts": []
      },
      {
       "name": "Nose",
       "why": "Nose is an older Python test runner built on unittest; pick it only to keep an old suite running as it is.",
       "path": "tools/nose/",
       "facts": []
      }
     ],
     "more": "Compare pytest with another tool",
     "more_path": "tools/compare/"
    }
   ]
  },
  {
   "id": "start",
   "nav": "Get started",
   "h2": "Get started",
   "parts": [
    {
     "t": "prompt",
     "text": "Add pytest (pin pytest==9.2.0, Python 3.10+) as a dev dependency, write tests in tests/test_*.py for the main functions with fixtures, parametrize and tmp_path, run python -m pytest -q and fix the code until every test passes."
    },
    {
     "t": "steps",
     "items": [
      {
       "text": "Install pytest into your project's virtual environment, not into the system Python.",
       "code": "python3 -m venv .venv\nsource .venv/bin/activate   # on Windows: .venv\\Scripts\\activate\npip install -U pytest\n",
       "src": "https://docs.pytest.org/en/stable/getting-started.html"
      },
      {
       "text": "Write a file whose name starts with test_ and put plain assert lines in functions whose names start with test_.",
       "code": "# content of test_sample.py\ndef func(x):\n    return x + 1\n\n\ndef test_answer():\n    assert func(3) == 5\n",
       "src": "https://docs.pytest.org/en/stable/getting-started.html"
      },
      {
       "text": "Run pytest in the project folder; it finds the test files and prints a report for each failure.",
       "code": "$ pytest",
       "src": "https://docs.pytest.org/en/stable/getting-started.html"
      }
     ]
    },
    {
     "t": "h3",
     "text": "Mistakes to avoid"
    },
    {
     "t": "mistakes",
     "items": [
      {
       "dont": "async def test_fetch(): ... with plain pytest",
       "fix": "Install an async plugin (pytest-asyncio or anyio) and mark the test as that plugin's docs say",
       "why": "In our run with pytest 9.2.0 the test failed with \"async def functions are not natively supported\" and a list of plugins."
      },
      {
       "dont": "@pytest.mark.parametrize(\"a\", [1, 2], True, [\"one\", \"two\"])  # indirect and ids passed by position",
       "fix": "@pytest.mark.parametrize(\"a\", [1, 2], indirect=True, ids=[\"one\", \"two\"])",
       "why": "Since pytest 9.2.0 indirect, ids and scope are keyword-only and positional use raises a TypeError."
      },
      {
       "dont": "Tests in tests/ fail with ModuleNotFoundError for the app's own module when the code lives in src/",
       "fix": "Install the project in editable mode, or set pythonpath = [\"src\"] in the pytest config",
       "why": "Without an editable install pytest does not see the src folder; our demo used pythonpath = [\".\"] for a flat folder."
      },
      {
       "dont": "Adding [tool.pytest] to pyproject.toml while [tool.pytest.ini_options] is still there",
       "fix": "Keep one of the two tables; the native [tool.pytest] table needs pytest 9.0 or newer",
       "why": "pytest 9.0 added the native TOML table but does not accept both tables at once."
      },
      {
       "dont": "A test class named CheckCart or a file named cart_tests.py",
       "fix": "Name files test_*.py or *_test.py and classes Test*, with test_* functions inside",
       "why": "Other names are not collected, so the tests silently never run."
      }
     ]
    }
   ]
  },
  {
   "id": "faq",
   "nav": "Questions",
   "h2": "Questions",
   "parts": [
    {
     "t": "faq",
     "items": [
      {
       "q": "Do I need special check functions like assertEqual?",
       "a": "No. You write plain Python assert lines, and pytest shows the values on both sides when one fails.",
       "evidence": {
        "url": "https://docs.pytest.org/en/stable/how-to/assert.html",
        "quote": "pytest allows you to use the standard Python assert for verifying expectations and values in Python tests."
       }
      },
      {
       "q": "Can I use it in a commercial project?",
       "a": "Yes. It is under the MIT license, which allows commercial use.",
       "evidence": {
        "url": "https://github.com/pytest-dev/pytest/blob/main/README.rst",
        "quote": "Distributed under the terms of the MIT license, pytest is free and open source software."
       }
      },
      {
       "q": "How do tests get shared setup like a sample cart or a database?",
       "a": "Through fixtures. A test names a fixture as an argument and pytest passes in what the fixture returns.",
       "evidence": {
        "url": "https://docs.pytest.org/en/stable/how-to/fixtures.html",
        "quote": "At a basic level, test functions request fixtures they require by declaring them as arguments."
       }
      },
      {
       "q": "Will my old unittest tests run?",
       "a": "Yes. pytest runs unittest suites without changes.",
       "evidence": {
        "url": "https://github.com/pytest-dev/pytest/blob/main/README.rst",
        "quote": "Can run unittest (or trial) test suites out of the box"
       }
      },
      {
       "q": "Is it still maintained?",
       "a": "Yes. Version 9.2.0 came out on 27 October 2026.",
       "evidence": {
        "url": "https://docs.pytest.org/en/stable/changelog.html",
        "quote": "pytest 9.2.0 (2026-10-27)"
       }
      }
     ]
    }
   ]
  }
 ],
 "glance": [
  [
   "Package",
   "pypi pytest"
  ],
  [
   "Category",
   "Testing"
  ],
  [
   "License",
   "MIT"
  ],
  [
   "Gid Score",
   "80.8"
  ],
  [
   "Rank in category",
   "#6 of 122"
  ],
  [
   "GitHub",
   "pytest-dev/pytest"
  ],
  [
   "Last change",
   "Nov 24, 2026"
  ]
 ],
 "good": [
  "The current version needs Python 3.10 or newer.",
  "Tests written with async def do not run on their own; you add a helper plugin such as pytest-asyncio or anyio.",
  "pytest only picks up files named test_*.py or *_test.py, and classes whose names start with Test; other names are skipped without a warning."
 ],
 "checked_line": "Read by AgentGid from 15 official pages, card checked Nov 11, 2026; numbers update daily.",
 "logo": "https://agentgid.com/media/avatars/pytest-dev.png"
}