{"id":14958071,"url":"https://github.com/pytorch/expecttest","last_synced_at":"2025-12-11T21:02:40.056Z","repository":{"id":60721091,"uuid":"379711067","full_name":"pytorch/expecttest","owner":"pytorch","description":null,"archived":false,"fork":false,"pushed_at":"2024-12-11T15:31:45.000Z","size":47,"stargazers_count":77,"open_issues_count":6,"forks_count":8,"subscribers_count":9,"default_branch":"main","last_synced_at":"2025-03-31T08:12:12.201Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/pytorch.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-06-23T19:36:45.000Z","updated_at":"2025-03-27T00:12:42.000Z","dependencies_parsed_at":"2024-06-18T20:10:33.727Z","dependency_job_id":"c38d92f4-6043-4538-b7c0-67807aa3b792","html_url":"https://github.com/pytorch/expecttest","commit_stats":{"total_commits":30,"total_committers":6,"mean_commits":5.0,"dds":0.5666666666666667,"last_synced_commit":"b2b87664b81f65856f17f36cb6dada7acdb0330c"},"previous_names":["pytorch/expecttest","ezyang/expecttest"],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pytorch%2Fexpecttest","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pytorch%2Fexpecttest/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pytorch%2Fexpecttest/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pytorch%2Fexpecttest/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pytorch","download_url":"https://codeload.github.com/pytorch/expecttest/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247640462,"owners_count":20971557,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-09-24T13:16:09.468Z","updated_at":"2025-12-11T21:02:34.718Z","avatar_url":"https://github.com/pytorch.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# expecttest [![PyPI version](https://badge.fury.io/py/expecttest.svg)](https://badge.fury.io/py/expecttest)\n\nThis library implements expect tests (also known as \"golden\" tests). Expect\ntests are a method of writing tests where instead of hard-coding the expected\noutput of a test, you run the test to get the output, and the test framework\nautomatically populates the expected output.  If the output of the test changes,\nyou can rerun the test with the environment variable `EXPECTTEST_ACCEPT=1` to\nautomatically update the expected output.\n\nSomewhat unusually, this library implements *inline* expect tests: that is to\nsay, the expected output isn't saved to an external file, it is saved directly\nin the Python file (and we modify your Python file when updating the expect\ntest.)\n\nThe general recipe for how to use this is as follows:\n\n  1. Write your test and use `assertExpectedInline()` instead of a normal\n     `assertEqual`.  Leave the expected argument blank with an empty string:\n     ```py\n     self.assertExpectedInline(some_func(), \"\"\"\"\"\")\n     ```\n\n  2. Run your test.  It should fail, and you get an error message about\n     accepting the output with `EXPECTTEST_ACCEPT=1`\n\n  3. Rerun the test with `EXPECTTEST_ACCEPT=1`.  Now the previously blank string\n     literal will contain the expected value of the test.\n     ```py\n     self.assertExpectedInline(some_func(), \"\"\"my_value\"\"\")\n     ```\n\n## A minimal working example\n\n```python\n# test.py\nimport unittest\nfrom expecttest import TestCase\n\nclass TestStringMethods(TestCase):\n    def test_split(self):\n        s = 'hello world'\n        self.assertExpectedInline(str(s.split()), \"\"\"\"\"\")\n\nif __name__ == '__main__':\n    unittest.main()\n```\n\nRun `EXPECTTEST_ACCEPT=1 python test.py` , and the content in triple-quoted string\nwill be automatically updated.\n\nFor people who use `pytest`:\n\n```python\nfrom expecttest import assert_expected_inline\n\ndef test_split():\n    s = 'hello world'\n    assert_expected_inline(str(s.split()), \"\"\"\"\"\")\n```\n\nRun `EXPECTTEST_ACCEPT=1 pytest test.py` , and the content in triple-quoted string\nwill be automatically updated.\n\nFor parameterized tests, advanced fixturing and other cases where the\nexpectation is in a different place than the assertion, use `Expect`:\n\n```python\nfrom expecttest import Expect\n\ndef test_removing_spaces(s: str, expected: Expect) -\u003e None:\n    expected.assert_expected(s.replace(\" \", \"\"))\n\ntest_removing_spaces(\"foo bar\", Expect(\"\"\"foobar\"\"\"))\ntest_removing_spaces(\"foo bar !!\", Expect(\"\"\"\"\"\"))\n```\n\nRun `EXPECTTEST_ACCEPT=1 pytest test.py` , and the content in triple-quoted string\nwill be automatically updated.\n\n## Some tips and tricks\n\n  - Often, you will want to expect test on a multiline string.  This framework\n    understands triple-quoted strings, so you can just write `\"\"\"my_value\"\"\"`\n    and it will turn into triple-quoted strings.\n\n  - Take some time thinking about how exactly you want to design the output\n    format of the expect test.  It is often profitable to design an output\n    representation specifically for expect tests.\n\n## Similar libraries\n\n- [expect-test](https://docs.rs/expect-test) for Rust\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpytorch%2Fexpecttest","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpytorch%2Fexpecttest","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpytorch%2Fexpecttest/lists"}