-
Notifications
You must be signed in to change notification settings - Fork 4
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
Warn about over-qualified actors #86
Comments
This is an interesting idea; sort of like a Screenplay Pattern auditor? I like the idea of making it a plugin, or some kind of alternate Maybe we could alter the |
Perhaps an alternate I'll think more about this feature. |
I just had one of those just-about-to-fall-asleep thoughts about this: We might be able to write an Ability that handles this! I'm thinking that if you want to verify your Actors aren't overqualified, you give them this Ability as their first Ability. This new Ability has overridden I'm guessing something like this, with the ability named import warnings
from typing import Generator
import pytest
from screenpy import AnActor, ComplainAboutOverqualification
from screenpy_selenium import BrowseTheWeb
from screenpy_requests import MakeAPIRequests
@pytest.fixture
def Callie() -> Generator:
the_actor = AnActor.named(Callie).who_cah(
ComplainAboutOverqualification(),
BrowseTheWeb.using_firefox(),
MakeAPIRequests(),
)
yield the_actor
# All of the below could be done in a new Action, like CheckQualifications or something
abilities_used = the_actor.uses_ability_to(ComplainAboutOverqualification).to_list_abilities_used() # ?
unused_abilities = set(the_actor.abilities) - abilities_used
if unused_abilities:
msg = f"Callie did not use {', '.join(map(str, unused_abilities)}."
warnings.warn(msg, ResourceWarning) Things i like about this approach:
Things i don't like:
What are your thoughts? Is this just a half-asleep fever dream and it's not as cool as it seems? |
Would a code coverage tool provide this? |
Just to bring back some learnings— I tried to implement my just-before-sleeping approach above using It doesn't look like there's a way to track this information without a new import warnings
from collections import defaultdict
from screenpy import Actor
from screenpy.actor import T_Ability
class SelfAuditingActor(Actor):
def uses_ability_to(self, ability: Type[T_Ability]) -> T_Ability:
"""Track the ability requested before supplying it."""
self.used_abilities[ability] += 1
return super().uses_ability_to(ability)
def exit(self) -> None:
"""Clean up, warn about any unused abilities."""
for ability, num_uses in self.used_abilities.items():
if num_uses == 0:
msg = f"{self.name} did not use {', '.join(map(str, unused_abilities)}."
warnings.warn(msg, ResourceWarning)
super().exit()
def __init__(self, name: str) -> None:
self.used_abilities = defaultdict(int)
super().__init__(name) I guess the question is, where would we put that? Should we have some kind of |
Recipes? |
Yeah, recipes is probably a good place to start it off. If we end up collecting more useful ways to audit your ScreenPy suite, then we can re-assess whether we branch it off into its own repo with specialized tools. How does that sound @rcavaz? Does the code above get you what you need? |
In other words, when reaching the end of test scenario, show a warning if an actor didn't used all of its abilities.
What problem would this solve?
I've been thinking for strategies to track feature coverage within a project and I believe Screenplay has potential in offering part of a solution.
Perhaps you might be familiar with the concept of Feature Modeling, which is essentially a way to represent different configurations of a software product.
In screenplay you assign abilities to actors so that they can interact with the system under test, but there's nothing stopping you from sticking to a single actor and assigning him/her with every possible ability in your suite. Hence, an over-qualified actor would be one who didn't use all of it's abilities within a certain scope of tests (so perhaps not just single scenarios).
Having such a warning would at least flag the opportunity for creating new, specialized, actors and facilitate tracking feature coverage.
Also, this would most likely be a plugin rather than a core feature.
Would be great to hear your thoughts and from the community in general.
The text was updated successfully, but these errors were encountered: