pytest-dev / pytest-dev/pytest-factoryboy

Allow disabling Subfactory fixture replacing - might create circular dependencies

Open
#69 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
400
Forks
44
Avg merge
6h 34m
Merged PRs (30d)
1

Description

Because pytest-factoryboy replaces SubFactory with registered factories, it is possible to inadvertently create circular dependencies, which are not detected by pytest.

In my case, the setup was the following:

  1. User factory
  2. Company factory with a Contact subfactory.
  3. user fixture overridden in the test file, depending on the company fixture
  4. contact fixture overridden in the same file, depending on the company fixture.

Normally it should be fine because user -> company and contact -> company - there's no cycle. But, because the plugin creates a dependency company -> contact, the graph becomes: user -> company -> contact -> company and there's a cycle. Yet this cycle is a bit magical - I did not ask for company.contact and contact.company to be the same... I want a new, unrelated contact to be created for each company.

Would it be possible to add an option to disable this for those who don't need it? Or only some whitelisted subfactories? In my case, I would like the company.contact factory to be unrelated to the contact factory.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by tracing how pytest-factoryboy replaces SubFactory with registered factories, using the User, Company, and Contact fixture setup described in the issue. Done means the replacement behavior can be disabled or limited to an explicit whitelist without creating the reported circular dependency.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
testing
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.