Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Print original bundle variable names in stateful mode #3902

Merged
merged 1 commit into from Feb 29, 2024

Conversation

fm4v
Copy link

@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
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
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
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
Copy link
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 merged commit 3745775 into HypothesisWorks:master Feb 29, 2024
48 checks passed
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.

None yet

2 participants