Skip to content

Commit

Permalink
Add environment variable alternatives for command line options (#36)
Browse files Browse the repository at this point in the history
  • Loading branch information
JamesHutchison committed Jun 16, 2023
1 parent c8e2be5 commit c835ead
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 6 deletions.
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,24 @@ the daemon.

The daemon can be stopped with `pytest --stop-daemon`. This can be used if it gets into a bad state.

## Arguments and Env Variables
- `PYTEST_DAEMON_PORT`
- The port the daemon listens on.
- Default: `4852`.
- Command line: `--daemon-port`
- `PYTEST_DAEMON_PYTEST_NAME`
- The name of the pytest executable.
- Default: `pytest`.
- Command line: `--pytest-name`
- `PYTEST_DAEMON_WATCH_GLOBS`
- The colon separated globs to watch.
- Default: `./**/*.py`.
- Command line: `--daemon-watch-globs`
- `PYTEST_DAEMON_IGNORE_WATCH_GLOBS`
- The colon separated globs to ignore.
- Default: `./.venv/*`.
- Command line: `--daemon-ignore-watch-globs`

## Workarounds
Libraries that use mutated globals may need a workaround to work with this plugin. The preferred
route is to have the library update its code to not mutate globals in a test environment, or to
Expand Down
12 changes: 6 additions & 6 deletions pytest_hot_reloading/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,31 +30,31 @@ def pytest_addoption(parser) -> None:
group.addoption(
"--daemon-port",
action="store",
default=4852,
default=int(os.getenv("PYTEST_DAEMON_PORT", "4852")),
help="The port to use for the daemon. You generally shouldn't need to set this.",
)
group.addoption(
"--pytest-name",
action="store",
default="pytest",
default=os.getenv("PYTEST_DAEMON_PYTEST_NAME", "pytest"),
help="The name of the pytest executable or module",
)
group.addoption(
"--daemon-timeout",
action="store",
default=(5 * 60),
help="The timeout in seconds to wait on a test suite to finish",
default=os.getenv("PYTEST_DAEMON_TIMEOUT", (5 * 60)),
help="The timeout in seconds to wait on a test suite to finish. This is not yet implemented.",
)
group.addoption(
"--daemon-watch-globs",
action="store",
default="./*.py",
default=os.getenv("PYTEST_DAEMON_WATCH_GLOBS", "./*.py"),
help="The globs to watch for changes. This is a colon separated list of globs.",
)
group.addoption(
"--daemon-ignore-watch-globs",
action="store",
default="./.venv/*",
default=os.getenv("PYTEST_DAEMON_IGNORE_WATCH_GLOBS", "./.venv/*"),
help="The globs to ignore for changes. This is a colon separated list of globs.",
)
group.addoption(
Expand Down

0 comments on commit c835ead

Please sign in to comment.