Title: fix(step): support attribute access in step title placeholders by golikovichev · Pull Request #910 · allure-framework/allure-python · GitHub
Open Graph Title: fix(step): support attribute access in step title placeholders by golikovichev · Pull Request #910 · allure-framework/allure-python
X Title: fix(step): support attribute access in step title placeholders by golikovichev · Pull Request #910 · allure-framework/allure-python
Description: Closes #896. Problem @allure.step("Process: {data.name}") raises AttributeError when data is an object with a name attribute (for example a dataclass), because func_parameters() converts every parameter value to its string representation before str.format() runs. By the time the title is being formatted, the values are already strings, so attribute access on {data.name} fails. Root cause In allure-python-commons/src/allure_commons/utils.py, func_parameters() applies represent() to every value at the moment it builds the parameter mapping: sorted_items = sorted( map( lambda kv: (kv[0], represent(kv[1])), # values become strings here items ), ... ) In _allure.py, the step decorator passed that already-stringified mapping to self.title.format(*args, **params), so {data.name} tried to access .name on a string and raised. Fix Introduce _StepTitleFormatter, a subclass of string.Formatter, that defers represent() to format_field, applied after attribute traversal. The decorator now hands the formatter the raw arguments (with defaults filled in from the function signature), so attribute traversal operates on the original objects. Leaf values are still wrapped via represent(), which preserves the existing repr-style display for plain positional and keyword placeholders. Behaviour Existing positional and keyword placeholders unchanged. Object attribute placeholders work: {data.name} traverses to the attribute and then applies represent() on the leaf value. Nested attribute access works: {user.address.city}. Method calls (self and cls first arg) continue to work. Default values for arguments are honoured, matching func_parameters(). Tests Added a new regression test file tests/allure_pytest/acceptance/step/step_attribute_placeholder_test.py covering: Dataclass attribute access in a step title. Plain object (non-dataclass) attribute access. Nested attribute access (user.address.city). All existing step tests continue to pass: tests/allure_pytest/acceptance/step/ ... 14 passed tests/allure_pytest/ (excluding pre-existing externals failures) ... 265 passed The 6 failures in tests/allure_pytest/externals/ reproduce on master without my changes (missing optional plugins such as pytest-check in the dev environment) and are unrelated to this PR.
Open Graph Description: Closes #896. Problem @allure.step("Process: {data.name}") raises AttributeError when data is an object with a name attribute (for example a dataclass), because func_parameters() converts ...
X Description: Closes #896. Problem @allure.step("Process: {data.name}") raises AttributeError when data is an object with a name attribute (for example a dataclass), because func_parameters() c...
Opengraph URL: https://github.com/allure-framework/allure-python/pull/910
X: @github
Domain: github.com
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /:user_id/:repository/pull/:id/files(.:format) |
| route-controller | pull_requests |
| route-action | files |
| fetch-nonce | v2:c6d8d897-0f66-82a7-6df4-111003826642 |
| current-catalog-service-hash | ae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b |
| request-id | 8E34:15BFB5:12A803:1972EA:6AFD4D12 |
| html-safe-nonce | a85f4eb33534bcfa0abb857bd8eabfd7dcd7119e91d87ffdb4296f25fea936ec |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4RTM0OjE1QkZCNToxMkE4MDM6MTk3MkVBOjZBRkQ0RDEyIiwidmlzaXRvcl9pZCI6IjE3OTMzNTg2Nzg1MDIyMzEzMTQiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 3744750f775a0e824032bfd453b3c94ef35fa66b352a54cca919901b69b8456b |
| hovercard-subject-tag | pull_request:3621125524 |
| github-keyboard-shortcuts | repository,pull-request-list,pull-request-conversation,pull-request-files-changed,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/allure-framework/allure-python/pull/910/files |
| twitter:image | https://avatars.githubusercontent.com/u/271386936?s=400&v=4 |
| twitter:card | summary_large_image |
| og:image | https://avatars.githubusercontent.com/u/271386936?s=400&v=4 |
| og:image:alt | Closes #896. Problem @allure.step("Process: {data.name}") raises AttributeError when data is an object with a name attribute (for example a dataclass), because func_parameters() converts ... |
| og:site_name | GitHub |
| og:type | object |
| hostname | github.com |
| expected-hostname | github.com |
| None | 66653c2e55a6fff2930be1bdf07ee4f8aa137e3956d056c822563be6f878755e |
| turbo-cache-control | no-preview |
| diff-view | unified |
| go-import | github.com/allure-framework/allure-python git https://github.com/allure-framework/allure-python.git |
| octolytics-dimension-user_id | 5879127 |
| octolytics-dimension-user_login | allure-framework |
| octolytics-dimension-repository_id | 79346720 |
| octolytics-dimension-repository_nwo | allure-framework/allure-python |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 79346720 |
| octolytics-dimension-repository_network_root_nwo | allure-framework/allure-python |
| turbo-body-classes | logged-out env-production page-responsive full-width |
| disable-turbo | true |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | b6f01f7cb9f35f8c09949773241a3d49dd04b340 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width