Skip to content

Config: remove more test specific conditions #1068

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

Open
wants to merge 1 commit into
base: 4.x
Choose a base branch
from

Conversation

jrfnl
Copy link
Member

@jrfnl jrfnl commented May 1, 2025

Description

The --cache option could not be tested as the Config class did not allow for it to be set in a test situation.

This "conditional ignore" was introduced in commit 24c7a7f around the same time the caching feature was introduced. The commit message doesn't give a reason for introducing the conditional ignore. I can only guess why and my guess would be that it was to prevent test runs being influence by dev-user specific system-wide defaults from a CodeSniffer.conf file.

In my opinion, that is not a good reason for keeping the "conditional ignore".

  • First of all, the default setting is for the cache to be off, so by default, tests wouldn't use the cache anyhow.
  • Second of all, the problem of interference from dev-user specific system-wide defaults was fixed by the introduction of the ConfigDouble and the AbstractRealConfigTestCase.

All in all, I think these conditions can be safely removed.

Do keep in mind though that subsequent test runs for tests involving caching may re-use the cache from an earlier run test.
To prevent that, set an explicit cacheFile for the test using --cache=<filename> and remove this cache file after running the test(s) via the tearDown[AfterClass]() method.

Note: one of the removed conditions also affected the --parallel option, but only for system-wide settings, not for CLI arguments.

Suggested changelog entry

N/A

Related issues/external references

Related to #966

The `--cache` option could not be tested as the `Config` class did not allow for it to be set in a test situation.

This "conditional ignore" was introduced in commit 24c7a7f around the same time the caching feature was introduced.
The commit message doesn't give a reason for introducing the conditional ignore. I can only guess why and my guess would be that it was to prevent test runs being influence by dev-user specific system-wide defaults from a `CodeSniffer.conf` file.

In my opinion, that is not a good reason for keeping the "conditional ignore".
* First of all, the default setting is for the cache to be _off_, so by default, tests wouldn't use the cache anyhow.
* Second of all, the problem of interference from dev-user specific system-wide defaults was fixed by the introduction of the `ConfigDouble` and the `AbstractRealConfigTestCase`.

All in all, I think these conditions can be safely removed.

Do keep in mind though that subsequent test runs for tests involving caching may re-use the cache from an earlier run test.
To prevent that, set an explicit cacheFile for the test using `--cache=<filename>` and remove this cache file after running the test(s) via the `tearDown[AfterClass]()` method.

Note: one of the removed conditions also affected the `--parallel` option, but only for system-wide settings, not for CLI arguments.

Related to 966
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant