You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Playwright配置workers为1后单测试仍被识别为2个并运行两次的问题求助

Playwright配置workers为1后单测试仍被识别为2个并运行两次的问题求助

我最近碰到了一个Playwright的诡异问题:明明已经在配置里把workers设为1,而且只写了一个测试用例,但运行的时候控制台却显示测试数量是2个,实际这个测试也真的跑了两次。

先贴一下我的配置片段:

timeout: 20 * 60 * 1000,
/* Run tests in files in parallel */
fullyParallel: false,
/* Fail the build on CI if you accidentally left test.only in the source code. */
forbidOnly: !!process.env.CI,
/* Retry on CI only */
retries: process.env.CI ? 1 : 0,
/* Opt out of parallel tests on CI. */
workers: 1,
/* Reporter to use. See https://playwright.dev/docs/test-reporters */

再给大家看一下我的测试结构:

test.describe("First Step", () => {
  test.beforeAll(async () => {
    // Setup code
  });

  test("Single test", async () => {
    // Test code
  });

  test.afterAll(async () => {
    // Teardown code
  });
});

但是当我运行这个唯一的测试时,控制台输出却是:

Running 2 tests using 1 worker

明明只定义了一个测试,Playwright却把它识别成两个,实际也执行了两次。

我已经尝试过的方法

  • 反复确认配置文件里的workers确实设置为1
  • 逐行检查测试结构,确保真的只有一个test()定义
  • 咨询过ChatGPT,但给出的调整建议都没能解决问题

我的目标

不管worker数量或者其他配置如何,我都需要这个测试只执行一次。

有没有朋友遇到过类似的问题?如果有的话,麻烦告诉我你是怎么解决的?

备注:内容来源于stack exchange,提问作者Md Shahnawaz Hussain

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.14 12:19:33