Introduce feature-based test directory structure#509
Conversation
6e44821 to
9a05335
Compare
9a05335 to
435bdb3
Compare
|
Test failures due to Galaxy: |
435bdb3 to
467b828
Compare
|
With this we have foreman-proxy marker applied to all tests in |
Technically You can certainly create a standalone file and if you have a bunch of tests it makes sense to create import pytest
pytestmark = pytest.mark.feature('bmc')
def test_x():
pass
def test_y():
passThis will be equivalent to (today) creating import pytest
pytestmark = [pytest.mark.feature('foreman-proxy'), pytest.mark.feature('bmc')]
def test_x():
pass
def test_y():
passBut you can also create import pytest
def test_base():
pass
@pytest.mark.feature('bmc')
def test_bmc():
passAll of these are functionally equivalent and it depends on how we want to organize it. |
|
Yes, I was thinking about marking the bmc feature dynamically, so when foreman-proxy is enabled, base_test.py runs the base proxy tests, and if bmc is also enabled, bmc_test.py runs the BMC-specific tests. Not blocking, just a thought to make things more dynamic |
|
As noted in #509 (comment), I've tried to avoid making things too dynamic and magical. I still remember https://code.djangoproject.com/wiki/RemovingTheMagic and think that's a good thing: I like it when things are easily predictable. |
Fair, thanks |
|
Lets give coderabbit a try @coderabbitai review |
|
✅ Actions performedReview triggered.
|
WalkthroughThis PR refactors pytest feature-marker application by introducing a pytest collection hook that automatically applies markers to test items based on directory location under Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes Possibly related PRs
Suggested reviewers
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
♻️ Duplicate comments (1)
tests/conftest.py (1)
246-257:⚠️ Potential issue | 🟡 Minor | ⚡ Quick winUse
item.pathinstead of deprecateditem.fspath.Line 250 uses
Path(item.fspath)which is deprecated in pytest. As previously suggested, useitem.path.relative_to(feature_dir)instead, which will also eliminate the need for thePathimport on line 4.Apply the previously suggested fix
-from pathlib import Pathdef pytest_collection_modifyitems(config, items): feature_dir = config.rootdir / 'tests' / 'feature' for item in items: try: - rel_path = Path(item.fspath).relative_to(feature_dir) + rel_path = item.path.relative_to(feature_dir) except ValueError: # Not in the features directory passVerify the deprecation status:
Is pytest's item.fspath deprecated in favor of item.path?🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@tests/conftest.py` around lines 246 - 257, Replace the deprecated use of item.fspath in pytest_collection_modifyitems with item.path: change rel_path = Path(item.fspath).relative_to(feature_dir) to rel_path = item.path.relative_to(feature_dir) (keep the existing try/except ValueError behavior), and remove the now-unused Path import at the top of the file; this targets the pytest_collection_modifyitems function and eliminates the deprecated item.fspath usage.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Duplicate comments:
In `@tests/conftest.py`:
- Around line 246-257: Replace the deprecated use of item.fspath in
pytest_collection_modifyitems with item.path: change rel_path =
Path(item.fspath).relative_to(feature_dir) to rel_path =
item.path.relative_to(feature_dir) (keep the existing try/except ValueError
behavior), and remove the now-unused Path import at the top of the file; this
targets the pytest_collection_modifyitems function and eliminates the deprecated
item.fspath usage.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 5afb9ce7-cb45-4d3a-8559-bfc1b332a090
📒 Files selected for processing (29)
docs/developer/testing.mdtests/conftest.pytests/feature/__init__.pytests/feature/foreman-proxy/__init__.pytests/feature/foreman-proxy/base_test.pytests/feature/foreman/__init__.pytests/feature/foreman/api_test.pytests/feature/foreman/base_test.pytests/feature/foreman/compute_resources_test.pytests/feature/foreman/plugins_test.pytests/feature/hammer/__init__.pytests/feature/hammer/base_test.pytests/feature/iop/__init__.pytests/feature/iop/test_advisor.pytests/feature/iop/test_advisor_frontend.pytests/feature/iop/test_cvemap_downloader.pytests/feature/iop/test_engine.pytests/feature/iop/test_gateway.pytests/feature/iop/test_ingress.pytests/feature/iop/test_integration.pytests/feature/iop/test_inventory.pytests/feature/iop/test_inventory_frontend.pytests/feature/iop/test_kafka.pytests/feature/iop/test_puptoo.pytests/feature/iop/test_remediation.pytests/feature/iop/test_vmaas.pytests/feature/iop/test_vulnerability.pytests/feature/iop/test_vulnerability_frontend.pytests/feature/iop/test_yuptoo.py
💤 Files with no reviewable changes (16)
- tests/feature/iop/test_kafka.py
- tests/feature/iop/test_remediation.py
- tests/feature/iop/test_inventory.py
- tests/feature/iop/test_vulnerability_frontend.py
- tests/feature/iop/test_advisor.py
- tests/feature/iop/test_advisor_frontend.py
- tests/feature/iop/test_inventory_frontend.py
- tests/feature/iop/test_yuptoo.py
- tests/feature/iop/test_cvemap_downloader.py
- tests/feature/iop/test_ingress.py
- tests/feature/iop/test_puptoo.py
- tests/feature/iop/test_vulnerability.py
- tests/feature/iop/test_integration.py
- tests/feature/iop/test_gateway.py
- tests/feature/iop/test_vmaas.py
- tests/feature/iop/test_engine.py
@coderabbitai appears to be unable to track file moves so it sees this as a new tests. |
|
Tip For best results, initiate chat on the files or code changes. 🧩 Analysis chain🏁 Script executed: Length of output: 266
✏️ Learnings added
|
Good to see AI accepting its mistakes gracefully 😄 |
|
@ekohl I applied the suggestion but broke Mind addressing that? |
802e11c to
a6fdd85
Compare
Fixed up the first commit to apply the suggestion and still keep ruff happy. I have a memory of doing so already, but I guess I never pushed that change. |
a6fdd85 to
1b235ab
Compare
|
Rebased to resolve a merge conflict: 50276b1 introduced |
|
@ekohl Can I ask you for another rebase? |
1b235ab to
fd7765f
Compare
|
Apologies, I missed your comment. Rebased now. |
b8e22f2 to
f9132e6
Compare
ehelms
left a comment
There was a problem hiding this comment.
I'm generally happy with this change, needs a rebase and will require rebases by most PRs we have open. I'm not sure there is ever going to be great timing so I say we just do it. @arvind4501 thoughts given your RFC?
This sets up a directory structure where an entire directory gets a feature mark. This makes it easy to skip entire feature tests.
f9132e6 to
305a0ad
Compare
|
Rebased to resolve the minor merge conflict. |
Why are you introducing these changes? (Problem description, related links)
Inspired by #485, but building on top of #508.
What are the changes introduced in this pull request?
It introduces a directory structure that automatically marks anything under
tests/feature/$featurewith$feature. This prepares for additional flavors that disable various features, such as a plain foreman (without katello) and a plain foreman-proxy.How to test this pull request
Steps to reproduce:
Checklist