Skip to content

Print original bundle variable names in stateful mode#3902

Merged
Zac-HD merged 1 commit into
HypothesisWorks:masterfrom
fm4v:stateful-better-names
Feb 29, 2024
Merged

Print original bundle variable names in stateful mode#3902
Zac-HD merged 1 commit into
HypothesisWorks:masterfrom
fm4v:stateful-better-names

Conversation

@fm4v
Copy link
Copy Markdown

@fm4v fm4v commented Feb 28, 2024

I often use the output of stateful testing to see what tests are generated, and poor naming hinders understanding of the code. This PR changes the names of variables and rule arguments depending on the name of the bundle.

Here is example of how it look now, instead of v1,v2,v3,.. naming

state = CreateUserTest()
state.init()
created_user_0 = state.create_user(user=User(name='M', password=PlainPassword(password='kgtDCRmafB')))
deleted_user_0 = state.drop_user(user=created_user_0)
created_user_1 = state.create_user(user=User(name='o', password=NoPassword()))
deleted_user_1 = state.drop_user(user=created_user_1)
state.teardown()

@fm4v fm4v force-pushed the stateful-better-names branch 3 times, most recently from 8e90c32 to 80ee339 Compare February 28, 2024 16:37
Copy link
Copy Markdown
Member

@Zac-HD Zac-HD left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you so much @fm4v! I wish we'd thought of this years ago, and I'm really looking forward to both using it myself and shipping it to our users 😁

I've left one comment below about the linting/lambda thing; this otherwise looks fantastic and I expect to get it out very soon.

Comment on lines +377 to +386
for target in targets:
name = self._new_name(target)
self.__printer.singleton_pprinters.setdefault(
id(result), lambda obj, p, cycle: p.text(name)
)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The lint rule is pointing out that every single lambda you're defining here will print the name defined in the last loop iteration. I implemented that because it tends to catch real bugs!

As a result, I'm also nervous because the tests are passing, and so we must not have anthing that checks for correct printing of bundle names from a rule which returns multiple targets. Can you add a test for this? The lambda is easy to fix with a binding lambda obj, p, cycle, *, name=name: p.text(name).

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, there was a problem with printing results for several targets using multiple(), but it has now been fixed and covered with tests.

@fm4v fm4v force-pushed the stateful-better-names branch 3 times, most recently from 261edd0 to e2a9665 Compare February 29, 2024 08:54
@fm4v fm4v force-pushed the stateful-better-names branch from e2a9665 to cd51b85 Compare February 29, 2024 09:17
Copy link
Copy Markdown
Member

@Zac-HD Zac-HD left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks again!

@Zac-HD Zac-HD enabled auto-merge February 29, 2024 09:37
@Zac-HD Zac-HD merged commit 3745775 into HypothesisWorks:master Feb 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants