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

Allow enabling process isolation on suite/test base class #5838

Open
mondrake opened this issue May 19, 2024 · 1 comment
Open

Allow enabling process isolation on suite/test base class #5838

mondrake opened this issue May 19, 2024 · 1 comment
Labels
feature/configuration/xml feature/process-isolation Issues related to running tests in separate PHP processes type/enhancement A new idea that should be implemented

Comments

@mondrake
Copy link

Process isolation can only be set via attributes in test classes (either overall on a class or on a single method) or on execution level (with attribute in XML or as a command line argument).

It would be good to enable process isolation on a middle ground, for instance for an entire suite or at a test base class level.

Drupal completed support of PHPUnit 10 in https://www.drupal.org/project/drupal/issues/3417066, and we needed there to find a workaround for this - there are 5 test suites in configuration, 3 of which have tests that need to run in process isolation, the others don't.

Since for each test suite there's a base test class extending from TestCase, we resolved by extending the constructor and setting process isolation there:

  public function __construct(string $name) {
    parent::__construct($name);
    $this->setRunTestInSeparateProcess(TRUE);
  }

https://git.drupalcode.org/project/drupal/-/blame/11.x/core/tests/Drupal/KernelTests/KernelTestBase.php?ref_type=heads#L107-L113

Prior to PHPUnit 10, this was possible by overriding TestCase properties, but this is no longer possible. The workaround works, but extends a constructor marked @internal and we are exposed to potential changes.

@mondrake mondrake added the type/enhancement A new idea that should be implemented label May 19, 2024
@sebastianbergmann sebastianbergmann added feature/process-isolation Issues related to running tests in separate PHP processes feature/configuration/xml labels May 19, 2024
@longwave
Copy link

longwave commented May 23, 2024

Would it be possible to look for class level attributes in parent classes as well? Then we could specify #[RunTestsInSeparateProcesses] on the base class and it would automatically apply to all subclasses.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature/configuration/xml feature/process-isolation Issues related to running tests in separate PHP processes type/enhancement A new idea that should be implemented
Projects
None yet
Development

No branches or pull requests

3 participants