{"id":17031460,"url":"https://github.com/pr4bh4sh/delayed-assert","last_synced_at":"2025-12-12T00:59:37.533Z","repository":{"id":47005119,"uuid":"70240382","full_name":"pr4bh4sh/delayed-assert","owner":"pr4bh4sh","description":"Delayed aka. Soft assert for python","archived":false,"fork":false,"pushed_at":"2021-09-17T17:47:40.000Z","size":556,"stargazers_count":30,"open_issues_count":7,"forks_count":6,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-03-19T17:43:41.715Z","etag":null,"topics":["assertion-library","delayed-assert","pip","python","python-library","python-package","python3","soft-assert","testing"],"latest_commit_sha":null,"homepage":"https://pr4bh4sh.github.io/delayed-assert/","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"unlicense","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/pr4bh4sh.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-10-07T11:25:25.000Z","updated_at":"2024-12-11T16:52:07.000Z","dependencies_parsed_at":"2022-09-02T22:33:43.851Z","dependency_job_id":null,"html_url":"https://github.com/pr4bh4sh/delayed-assert","commit_stats":null,"previous_names":["pr4bh4sh/python-delayed-assert"],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pr4bh4sh%2Fdelayed-assert","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pr4bh4sh%2Fdelayed-assert/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pr4bh4sh%2Fdelayed-assert/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pr4bh4sh%2Fdelayed-assert/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pr4bh4sh","download_url":"https://codeload.github.com/pr4bh4sh/delayed-assert/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248571576,"owners_count":21126519,"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":["assertion-library","delayed-assert","pip","python","python-library","python-package","python3","soft-assert","testing"],"created_at":"2024-10-14T08:24:18.227Z","updated_at":"2025-12-12T00:59:37.526Z","avatar_url":"https://github.com/pr4bh4sh.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![Tests](https://github.com/pr4bh4sh/delayed-assert/actions/workflows/tests.yml/badge.svg)](https://github.com/pr4bh4sh/delayed-assert/actions/workflows/tests.yml)\n[![PyPI version](https://badge.fury.io/py/delayed-assert.svg)](https://badge.fury.io/py/delayed-assert)\n[![Downloads](https://pepy.tech/badge/delayed-assert)](https://pepy.tech/project/delayed-assert)\n[![Downloads](https://pepy.tech/badge/delayed-assert/month)](https://pepy.tech/project/delayed-assert)\n\n# Python-Delayed-Assert\n\nDelayed aka. Soft asserts for python\n\nFew features:\n\n    - No Dependenices on any other framework/library.\n    - Should work with any testing framework.\n    - Can be use as decorator or context manager.\n\n![Sample](https://raw.githubusercontent.com/pr4bh4sh/delayed-assert/master/sample.jpg)\n\n## Installation\n\n### Install via pip\n\n```bash\n    pip install delayed-assert\n```\n\n### Install from master\n\n```bash\n    pip install git+https://github.com/pr4bh4sh/delayed-assert\n```\n\n## Uses\n\nSee `tests/example_unittest.py` for usage.\n\n### Using assertion library with lambda\n\nPass the assertion call as\n\n```python\n    expect(lambda: self.assertListEqual([4,5,6,2,5],[7,8]))\n```\n\nWhile I've tested only with unittest asserttion,It should be able to use any assertion library.\n\nKeep in mind that, Python does not support statement inside lambda, so\n\n```python\n    expect(lambda: assert 1 == 1)\n```\n\nwon't work as it is not a valid lambda expression in python\n\n### Current possible uses\n\n```python\n    def testSomething(self):\n        delayed_assert.expect(1 == 1) # will succeed\n        delayed_assert.expect(1 == 2) # will fail but won't stop execution\n        delayed_assert.expect(3 == 2, \"Value don't match\") # will fail but won't stop execution\n        delayed_assert.expect(3 == 3) # will succeed\n        # will stop execution and show the stack trace of 2nd assertion\n        delayed_assert.assert_expectations()\n\n    def testLambdas(self):\n        expect(lambda: self.assertEqual(3,4)) # will fail but won't stop execution\n        expect(lambda: self.assertListEqual([4,5,6,2,5],[7,8])) # will fail but won't stop execution\n        assert_expectations()\n\n    @delayed_assert.assert_all()\n    def testDecorator(self):\n        expect('five' == 'Six', 'String do not match')\n        expect([5,2] == [3,4], 'List item do not match')\n        expect([3,4] == [3,4], 'This message wont be printed')\n        # No need to call delayed_assert.assert_expectations() when decorator is used\n    \n    def testContextManeger(self):\n        with delayed_assert.assert_all():\n            expect('four' == 'Six', 'String do not match')\n            expect([5,2] == [3,4], 'List item do not match')\n            expect([3,4] == [3,4], 'This message wont be printed')\n            # No need to call delayed_assert.assert_expectations() when using context maneger is used\n\n    # Use @test_case to identify helper methods or non-standard test names\n    @delayed_assert.test_case\n    def verify_something_helper(self):\n        expect(1 == 1)\n\n\n```\n\n---------------\n\n## Color Output Control\n\nThe library supports toggling colorized output on/off via environment variable or programmatically.\n\n### Disable Colors via Environment Variable\n\n```bash\n# Disable colors\nDELAYED_ASSERT_ENABLE_COLOR=0 python -m unittest example_unittest.py\n\n# Enable colors (default)\nDELAYED_ASSERT_ENABLE_COLOR=1 python -m unittest example_unittest.py\n```\n\nValues that disable colors: `0`, `false`, `no`, `off` (case-insensitive)\n\n### Disable Colors Programmatically\n\n```python\nfrom delayed_assert.delayed_assert import set_color_enabled, get_color_enabled\n\n# Disable colors\nset_color_enabled(False)\n\n# Check status\nif get_color_enabled():\n    print(\"Colors are enabled\")\n```\n\nThis is useful for:\n- CI/CD environments where ANSI color codes may not be supported\n- Log files where color codes create noise\n- Environments with accessibility requirements\n\n### Caller Stack Verification\n\nBy default, the library verifies that `expect()` is called from a method named `test*`. \nYou can disable this check if you need to use `expect()` in helper methods or custom test runners.\n\n**Disable via Environment Variable:**\n```bash\nDELAYED_ASSERT_CHECK_CALLER=0 python -m unittest example_unittest.py\n```\n\n**Disable Programmatically:**\n```python\nfrom delayed_assert.delayed_assert import set_check_caller\n\nset_check_caller(False)\n```\n\n**Using the `@test_case` Decorator:**\n\nAlternatively, you can mark any function as a test case using the `@test_case` decorator. This allows `expect()` to identify the function correctly without disabling verificaton globally.\n\n```python\nfrom delayed_assert import expect, assert_expectations, test_case\n\n@test_case\ndef verify_custom_scenario():\n    expect(1 == 1, \"Should pass\")\n\ndef test_runner():\n    verify_custom_scenario()\n    assert_expectations()\n```\n\n---------------\n\nCredit : \u003chttp://pythontesting.net/strategy/delayed-assert/\u003e\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpr4bh4sh%2Fdelayed-assert","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpr4bh4sh%2Fdelayed-assert","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpr4bh4sh%2Fdelayed-assert/lists"}