ScreenPyHQ / screenpy

Screenplay pattern base for Python automated UI test suites.
MIT License
28 stars 4 forks source link

#51: Refactor settings. #69

Closed perrygoy closed 1 year ago

perrygoy commented 1 year ago

Boy it would be nice to be able to dynamically and programmatically alter our settings, instead of having to do import settings and settings.TIMEOUT = 50. Other projects can use pyproject.toml or environment variables... man it sure would be—HEY WHOA check out this PR!

It does exactly those things i said!

This PR adds Pydantic to our settings soup, and some handling for investigating pyproject.toml as a source for settings. It also adds some nice documentation using autodoc_pydantic to document our default settings.

bandophahita commented 1 year ago

I mentioned this in discord; I see a potential problem with users who upgrade to this latest version. They do not receive any warning when they were doing the following (prior to update):

#conftest.py
from screenpy import settings

settings.TIMEOUT = 2
settings.POLLING = 0.1

I think we should rename settings.py to something else. Plus if we renamed the object config to settings it would be backwards compatible. They shouldn't need to change any of their existing code.

bandophahita commented 1 year ago

Users can't set the screenpy.narration.stdout_adapter settings after StdOutManager has been initialized.

Adjusting the log method ought to fix that.

    def log(self, line: str, level: int = logging.INFO) -> None:
        """Log a line!"""
        indent = len(self.depth) * (settings.INDENT_SIZE * settings.INDENT_CHAR) if settings.INDENT_LOGS else ""
        self.logger.log(level, f"{indent}{line}")
perrygoy commented 1 year ago

I got verbal approval from @bandophahita on Slack before he was done for the day, so i don't feel too bad force-merging!