Start pytest with all plugins disabled

Viewed 549

I've been debugging a weird pytest startup issue and wanted to check if any of the plugins is causing a problem.

Is it possible to start pytest and ask it to not load any of the plugins?

From what I see in the documentation, there is a way to only turn off a specific plugin by name.

1 Answers

Posting a solution recommended in the comments:

python -c "import pkg_resources; print(' '.join('-p no:' + ' '.join(dist.get_entry_map(group='pytest11').keys()) for dist in pkg_resources.working_set if dist.get_entry_map(group='pytest11')))" | xargs pytest

This looks a bit magical, but, if analyzed and broken down, it starts to make more sense:

  • pkg_resources is a part of setuptools which allows to access package resource files, configs and setup configurations
  • .get_entry_map() returns the dictionary of "entry point" objects
  • we are filtering out pytest11 entry points as this is what Pytest itself is using to discover plugins
  • then, we are feeding the filtered out entry points into the -p no: command line argument which is a Pytest's way to disable a plugin

Inspired by this answer.

Related