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

Fix PytestRun to honor user conftest.py plugins. #7784

Merged
merged 2 commits into from
May 21, 2019

Conversation

jsirois
Copy link
Contributor

@jsirois jsirois commented May 21, 2019

Previously codebases that leveraged pytest's conftest.py support could
fail when tested with ./pants test in various situations. This was
ultimately because we injected our own conftest.py to register our
custom pytest plugins and plugin discovery of conftest.py plugins is
brittle. We avoid the brittleness by moving our plugin into a sys.path
module activated with -p fixing a previously failing test added in
test_conftests_discovery_with_coverage.

Previously codebases that leveraged pytest's `conftest.py` support could
fail when tested with pants test in various situations. This was
ultimately because we injected out own `conftest.py` to register our
custom pytest plugins and plugin discovery of `conftest.py` plugins is
brittle. We avoid the brittleness by moving our plugin into a `sys.path`
module activated with `-p` fixing a previously failing test added in
`test_conftests_discovery_with_coverage`.
import pytest


class NodeRenamerPlugin(object):
Copy link
Contributor Author

@jsirois jsirois May 21, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NB: This is mainly a move from _get_conftest_content on the LHS.

item._nodeid = real_nodeid


class ShardingPlugin(object):
Copy link
Contributor Author

@jsirois jsirois May 21, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NB: This is mainly a move from _get_shard_conftest_content on the LHS.

Copy link
Member

@asherf asherf left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't have enough context on this repo to give a useful review. but looks fine to me.

@jsirois
Copy link
Contributor Author

jsirois commented May 21, 2019

I'm going to submit but I'll circle back if there is any further feedback.

@jsirois jsirois merged commit b3cdd8a into pantsbuild:master May 21, 2019
@jsirois jsirois deleted the pytest/dont-pollute-conftest branch May 21, 2019 23:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants