Error: Playwright Test did not expect test() to be called here
Playwright found a test() call somewhere it can't register one. It's almost always two copies of @playwright/test, or a spec file importing another spec file.
Published
Why this happens
Two different versions of `@playwright/test` are installed (e.g. one hoisted in a monorepo root and one in the package), so `test` comes from a different instance than the runner
A spec file imports from another spec file, so that file's `test()` calls run at import time outside the runner's collection phase
`test()` is called inside a helper function, a loop that runs after collection, or inside another `test()` body
Both `playwright` and `@playwright/test` are installed and imported in different places
How to fix it
Run `npm ls @playwright/test` and dedupe until exactly one version is listed
Move shared helpers and fixtures out of `*.spec.ts` files into a plain module (e.g. `fixtures.ts`) and import from there
Keep `test()` calls at the top level of the spec file or inside `test.describe()`, never inside another test or an async callback
Import `test` and `expect` only from `@playwright/test` (or your own fixtures file that extends it)
Example
// Bad: login.spec.ts imports a helper that lives in another spec file
import { loginAs } from './checkout.spec';
// Good: helpers live in a plain module, not a spec file
// helpers/auth.ts
export async function loginAs(page: Page, user: string) { /* ... */ }
// login.spec.ts
import { loginAs } from './helpers/auth';