Skip to content

Enable ruff B015 to catch silent no-op comparisons in tests - #66977

Merged
shahar1 merged 5 commits into
apache:mainfrom
shahar1:enable-ruff-b015-useless-comparison
May 16, 2026
Merged

Enable ruff B015 to catch silent no-op comparisons in tests#66977
shahar1 merged 5 commits into
apache:mainfrom
shahar1:enable-ruff-b015-useless-comparison

Conversation

@shahar1

@shahar1shahar1 commented May 15, 2026

Copy link
Copy Markdown
Contributor

Bare actual == expected expressions in tests silently evaluate and discard their result — the test passes regardless of correctness. This is exactly what happened in #66894 (four test_serialize methods in the Vertex AI triggers had been vacuously passing for years).

Changes

  • pyproject.toml: add B015 (useless-comparison) to extend-select. This rule fires on any bare comparison expression used as a statement.
  • 16 test files: add the missing assert to all 26 existing violations found by the rule across airflow-core, task-sdk, and providers amazon, cncf/kubernetes, google).

With this in place, any future bare comparison in a test is a lint error caught before CI runs.


Was generative AI tooling used to co-author this PR?
  • Yes — Claude Code (Sonnet 4.6)

Generated-by: Claude Code (Sonnet 4.6) following the guidelines

@boring-cyborgboring-cyborgBot added area:CLI area:DAG-processing area:providers area:Scheduler including HA (high availability) scheduler area:task-sdk provider:amazon AWS/Amazon - related issues provider:cncf-kubernetes Kubernetes (k8s) provider related issues provider:google Google (including GCP) related issues labels May 15, 2026
Bare `actual == expected` expressions (missing `assert`) silently pass
regardless of correctness. Enable ruff rule B015 (useless-comparison)
to make this a lint error, and add `assert` to all 26 existing instances
found across airflow-core, task-sdk, and providers (amazon, cncf, google).
@shahar1
shahar1force-pushed the enable-ruff-b015-useless-comparison branch from ff2e36f to 7dfec04CompareMay 15, 2026 05:01
@shahar1
shahar1 requested review from Lee-W and jason810496May 15, 2026 05:20
@shahar1
shahar1 marked this pull request as draft May 15, 2026 05:36
`.calls` is not a real MagicMock attribute; accessing it auto-creates a
child MagicMock. The expression `mock.calls[0] == []` was a silent no-op
that B015 correctly caught. Adding `assert` exposed that the comparison
always evaluates to False.
Replace with `assert_not_called()`, which correctly verifies that
`revoke_task` routes through `kube_scheduler.patch_pod_revoked()` rather
than calling `patch_namespaced_pod` directly.
@shahar1
shahar1 marked this pull request as ready for review May 15, 2026 05:50
@shahar1
shahar1 marked this pull request as draft May 15, 2026 06:29
- test_bedrock: set ensure_unique_job_name on the operator before execute
so the not-ensure-unique parametrize cases actually test the right path,
and use pytest.raises for the cases where a conflict error is expected
- test_emr_serverless (create): remove dead get_application mock setup and
wrong call-count assertion; the operator uses waiters, not direct polling
- test_emr_serverless (start job): correct expected call_count from 2 to 1;
the operator calls get_application once (state CREATED is in SUCCESS_STATES
so no retry loop)
@shahar1
shahar1 marked this pull request as ready for review May 15, 2026 06:37

@jscheffljscheffl left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Cool! I assume you can work on making CI green in parallel :-D

- Add missing `assert` to three bare comparisons caught by the new
B015 rule: test_pod_template_file.py, test_otel_logger.py (×2)
- Fix the MappedOperator task_type assertion in test_dag_serialization:
`type(task).__name__` gives the wrapper class (`DecoratedMappedOperator`)
but `operator_class["task_type"]` stores the underlying operator's name
(`task.operator_class.__name__`, e.g. `_PythonDecoratedOperator`)
@shahar1
shahar1 requested a review from potiuk as a code ownerMay 15, 2026 15:55
@shahar1
shahar1 requested a review from bugraoz93 as a code ownerMay 15, 2026 15:55
The operator uses json.dump() which writes strings incrementally to the
file handle; the previous assertion expected bytes in a single write call.
Also adds the missing mock_file.write.reset_mock() between the CSV and
JSON sub-tests so write calls don't accumulate across sections.
@shahar1
shahar1 merged commit 2ed6805 into apache:mainMay 16, 2026
292 checks passed
@shahar1
shahar1 deleted the enable-ruff-b015-useless-comparison branch May 16, 2026 05:24
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:CLIarea:DAG-processingarea:providersarea:Schedulerincluding HA (high availability) schedulerarea:task-sdkprovider:amazonAWS/Amazon - related issuesprovider:cncf-kubernetesKubernetes (k8s) provider related issuesprovider:googleGoogle (including GCP) related issues

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

@shahar1@Lee-W@jscheffl
, 'i'); if (__m === '*' || __re.test(location.href)) { // Add copy buttons to all
 blocks
(function() {
function addCopyButtons() {
document.querySelectorAll('pre code').forEach(function(codeBlock) {
if (codeBlock.parentElement.hasAttribute('data-copy-added')) return;
codeBlock.parentElement.setAttribute('data-copy-added', 'true');
var btn = document.createElement('button');
btn.textContent = 'Copy';
btn.style.cssText = 'position:absolute;top:4px;right:4px;padding:2px 8px;font-size:11px;background:#4ecdc4;border:none;border-radius:4px;color:#1a1a2e;cursor:pointer;opacity:0.7;transition:opacity 0.2s;';
btn.onmouseover = function() { this.style.opacity = '1'; };
btn.onmouseout = function() { this.style.opacity = '0.7'; };
btn.onclick = function() {
navigator.clipboard.writeText(codeBlock.textContent).then(function() {
btn.textContent = 'Copied!';
setTimeout(function() { btn.textContent = 'Copy'; }, 1500);
});
};
codeBlock.parentElement.style.position = 'relative';
codeBlock.parentElement.appendChild(btn);
});
}
addCopyButtons();
// Re-run on dynamic content
var observer = new MutationObserver(addCopyButtons);
observer.observe(document.body, { childList: true, subtree: true });
})();
}
} catch(__e) { console.warn('[Userscript:Add Copy Buttons to Code Blocks]', __e); }
})();
(function(){
try {
var __m = "github.com";
var __re = new RegExp('^' + "github\\.com" + '
Enable ruff B015 to catch silent no-op comparisons in tests by shahar1 · Pull Request #66977 · apache/airflow · GitHub
Skip to content

Enable ruff B015 to catch silent no-op comparisons in tests - #66977

Merged
shahar1 merged 5 commits into
apache:mainfrom
shahar1:enable-ruff-b015-useless-comparison
May 16, 2026
Merged

Enable ruff B015 to catch silent no-op comparisons in tests#66977
shahar1 merged 5 commits into
apache:mainfrom
shahar1:enable-ruff-b015-useless-comparison

Conversation

@shahar1

@shahar1shahar1 commented May 15, 2026

Copy link
Copy Markdown
Contributor

Bare actual == expected expressions in tests silently evaluate and discard their result — the test passes regardless of correctness. This is exactly what happened in #66894 (four test_serialize methods in the Vertex AI triggers had been vacuously passing for years).

Changes

  • pyproject.toml: add B015 (useless-comparison) to extend-select. This rule fires on any bare comparison expression used as a statement.
  • 16 test files: add the missing assert to all 26 existing violations found by the rule across airflow-core, task-sdk, and providers amazon, cncf/kubernetes, google).

With this in place, any future bare comparison in a test is a lint error caught before CI runs.


Was generative AI tooling used to co-author this PR?
  • Yes — Claude Code (Sonnet 4.6)

Generated-by: Claude Code (Sonnet 4.6) following the guidelines

@boring-cyborgboring-cyborgBot added area:CLI area:DAG-processing area:providers area:Scheduler including HA (high availability) scheduler area:task-sdk provider:amazon AWS/Amazon - related issues provider:cncf-kubernetes Kubernetes (k8s) provider related issues provider:google Google (including GCP) related issues labels May 15, 2026
Bare `actual == expected` expressions (missing `assert`) silently pass
regardless of correctness. Enable ruff rule B015 (useless-comparison)
to make this a lint error, and add `assert` to all 26 existing instances
found across airflow-core, task-sdk, and providers (amazon, cncf, google).
@shahar1
shahar1force-pushed the enable-ruff-b015-useless-comparison branch from ff2e36f to 7dfec04CompareMay 15, 2026 05:01
@shahar1
shahar1 requested review from Lee-W and jason810496May 15, 2026 05:20
@shahar1
shahar1 marked this pull request as draft May 15, 2026 05:36
`.calls` is not a real MagicMock attribute; accessing it auto-creates a
child MagicMock. The expression `mock.calls[0] == []` was a silent no-op
that B015 correctly caught. Adding `assert` exposed that the comparison
always evaluates to False.
Replace with `assert_not_called()`, which correctly verifies that
`revoke_task` routes through `kube_scheduler.patch_pod_revoked()` rather
than calling `patch_namespaced_pod` directly.
@shahar1
shahar1 marked this pull request as ready for review May 15, 2026 05:50
@shahar1
shahar1 marked this pull request as draft May 15, 2026 06:29
- test_bedrock: set ensure_unique_job_name on the operator before execute
so the not-ensure-unique parametrize cases actually test the right path,
and use pytest.raises for the cases where a conflict error is expected
- test_emr_serverless (create): remove dead get_application mock setup and
wrong call-count assertion; the operator uses waiters, not direct polling
- test_emr_serverless (start job): correct expected call_count from 2 to 1;
the operator calls get_application once (state CREATED is in SUCCESS_STATES
so no retry loop)
@shahar1
shahar1 marked this pull request as ready for review May 15, 2026 06:37

@jscheffljscheffl left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Cool! I assume you can work on making CI green in parallel :-D

- Add missing `assert` to three bare comparisons caught by the new
B015 rule: test_pod_template_file.py, test_otel_logger.py (×2)
- Fix the MappedOperator task_type assertion in test_dag_serialization:
`type(task).__name__` gives the wrapper class (`DecoratedMappedOperator`)
but `operator_class["task_type"]` stores the underlying operator's name
(`task.operator_class.__name__`, e.g. `_PythonDecoratedOperator`)
@shahar1
shahar1 requested a review from potiuk as a code ownerMay 15, 2026 15:55
@shahar1
shahar1 requested a review from bugraoz93 as a code ownerMay 15, 2026 15:55
The operator uses json.dump() which writes strings incrementally to the
file handle; the previous assertion expected bytes in a single write call.
Also adds the missing mock_file.write.reset_mock() between the CSV and
JSON sub-tests so write calls don't accumulate across sections.
@shahar1
shahar1 merged commit 2ed6805 into apache:mainMay 16, 2026
292 checks passed
@shahar1
shahar1 deleted the enable-ruff-b015-useless-comparison branch May 16, 2026 05:24
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:CLIarea:DAG-processingarea:providersarea:Schedulerincluding HA (high availability) schedulerarea:task-sdkprovider:amazonAWS/Amazon - related issuesprovider:cncf-kubernetesKubernetes (k8s) provider related issuesprovider:googleGoogle (including GCP) related issues

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

@shahar1@Lee-W@jscheffl
, 'i'); if (__m === '*' || __re.test(location.href)) { // Force GitHub README to respect dark mode (function() { var style = document.createElement('style'); style.textContent = ' .markdown-body { color-scheme: dark light; } .markdown-body pre { background: #161b22 !important; } .markdown-body code { background: rgba(110, 118, 129, 0.4) !important; } .markdown-body table th, .markdown-body table td { border-color: #30363d !important; } .markdown-body img { background: #0d1117; } .markdown-body blockquote { border-left-color: #8b949e; } .markdown-body hr { border-color: #30363d; } '; document.head.appendChild(style); })(); } } catch(__e) { console.warn('[Userscript:GitHub Dark Mode README Fix]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ' Enable ruff B015 to catch silent no-op comparisons in tests by shahar1 · Pull Request #66977 · apache/airflow · GitHub
Skip to content

Enable ruff B015 to catch silent no-op comparisons in tests - #66977

Merged
shahar1 merged 5 commits into
apache:mainfrom
shahar1:enable-ruff-b015-useless-comparison
May 16, 2026
Merged

Enable ruff B015 to catch silent no-op comparisons in tests#66977
shahar1 merged 5 commits into
apache:mainfrom
shahar1:enable-ruff-b015-useless-comparison

Conversation

@shahar1

@shahar1shahar1 commented May 15, 2026

Copy link
Copy Markdown
Contributor

Bare actual == expected expressions in tests silently evaluate and discard their result — the test passes regardless of correctness. This is exactly what happened in #66894 (four test_serialize methods in the Vertex AI triggers had been vacuously passing for years).

Changes

  • pyproject.toml: add B015 (useless-comparison) to extend-select. This rule fires on any bare comparison expression used as a statement.
  • 16 test files: add the missing assert to all 26 existing violations found by the rule across airflow-core, task-sdk, and providers amazon, cncf/kubernetes, google).

With this in place, any future bare comparison in a test is a lint error caught before CI runs.


Was generative AI tooling used to co-author this PR?
  • Yes — Claude Code (Sonnet 4.6)

Generated-by: Claude Code (Sonnet 4.6) following the guidelines

@boring-cyborgboring-cyborgBot added area:CLI area:DAG-processing area:providers area:Scheduler including HA (high availability) scheduler area:task-sdk provider:amazon AWS/Amazon - related issues provider:cncf-kubernetes Kubernetes (k8s) provider related issues provider:google Google (including GCP) related issues labels May 15, 2026
Bare `actual == expected` expressions (missing `assert`) silently pass
regardless of correctness. Enable ruff rule B015 (useless-comparison)
to make this a lint error, and add `assert` to all 26 existing instances
found across airflow-core, task-sdk, and providers (amazon, cncf, google).
@shahar1
shahar1force-pushed the enable-ruff-b015-useless-comparison branch from ff2e36f to 7dfec04CompareMay 15, 2026 05:01
@shahar1
shahar1 requested review from Lee-W and jason810496May 15, 2026 05:20
@shahar1
shahar1 marked this pull request as draft May 15, 2026 05:36
`.calls` is not a real MagicMock attribute; accessing it auto-creates a
child MagicMock. The expression `mock.calls[0] == []` was a silent no-op
that B015 correctly caught. Adding `assert` exposed that the comparison
always evaluates to False.
Replace with `assert_not_called()`, which correctly verifies that
`revoke_task` routes through `kube_scheduler.patch_pod_revoked()` rather
than calling `patch_namespaced_pod` directly.
@shahar1
shahar1 marked this pull request as ready for review May 15, 2026 05:50
@shahar1
shahar1 marked this pull request as draft May 15, 2026 06:29
- test_bedrock: set ensure_unique_job_name on the operator before execute
so the not-ensure-unique parametrize cases actually test the right path,
and use pytest.raises for the cases where a conflict error is expected
- test_emr_serverless (create): remove dead get_application mock setup and
wrong call-count assertion; the operator uses waiters, not direct polling
- test_emr_serverless (start job): correct expected call_count from 2 to 1;
the operator calls get_application once (state CREATED is in SUCCESS_STATES
so no retry loop)
@shahar1
shahar1 marked this pull request as ready for review May 15, 2026 06:37

@jscheffljscheffl left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Cool! I assume you can work on making CI green in parallel :-D

- Add missing `assert` to three bare comparisons caught by the new
B015 rule: test_pod_template_file.py, test_otel_logger.py (×2)
- Fix the MappedOperator task_type assertion in test_dag_serialization:
`type(task).__name__` gives the wrapper class (`DecoratedMappedOperator`)
but `operator_class["task_type"]` stores the underlying operator's name
(`task.operator_class.__name__`, e.g. `_PythonDecoratedOperator`)
@shahar1
shahar1 requested a review from potiuk as a code ownerMay 15, 2026 15:55
@shahar1
shahar1 requested a review from bugraoz93 as a code ownerMay 15, 2026 15:55
The operator uses json.dump() which writes strings incrementally to the
file handle; the previous assertion expected bytes in a single write call.
Also adds the missing mock_file.write.reset_mock() between the CSV and
JSON sub-tests so write calls don't accumulate across sections.
@shahar1
shahar1 merged commit 2ed6805 into apache:mainMay 16, 2026
292 checks passed
@shahar1
shahar1 deleted the enable-ruff-b015-useless-comparison branch May 16, 2026 05:24
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:CLIarea:DAG-processingarea:providersarea:Schedulerincluding HA (high availability) schedulerarea:task-sdkprovider:amazonAWS/Amazon - related issuesprovider:cncf-kubernetesKubernetes (k8s) provider related issuesprovider:googleGoogle (including GCP) related issues

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

@shahar1@Lee-W@jscheffl
, 'i'); if (__m === '*' || __re.test(location.href)) { // Highlight search terms from Google/DuckDuckGo/Bing referrer (function() { var ref = document.referrer; var terms = []; if (ref.includes('google.com') || ref.includes('duckduckgo.com') || ref.includes('bing.com')) { var url = new URL(ref); var q = url.searchParams.get('q') || url.searchParams.get('p'); if (q) { terms = q.split(/\s+/).filter(function(t) { return t.length > 2; }); } } if (terms.length === 0) return; var style = document.createElement('style'); style.textContent = '.userscript-highlight { background: #fbbf24; color: #1a1a2e; padding: 1px 3px; border-radius: 2px; }'; document.head.appendChild(style); function highlight(node) { if (node.nodeType === 3) { // text node var text = node.textContent; var found = false; terms.forEach(function(term) { var regex = new RegExp('(' + term.replace(/[.*+?^${}()|[\]\\]/g, '\\') + ')', 'gi'); if (regex.test(text)) { found = true; var frag = document.createDocumentFragment(); var parts = text.split(regex); parts.forEach(function(part, i) { if (i % 2 === 0) { frag.appendChild(document.createTextNode(part)); } else { var span = document.createElement('span'); span.className = 'userscript-highlight'; span.textContent = part; frag.appendChild(span); } }); node.parentNode.replaceChild(frag, node); } }); } else if (node.nodeType === 1 && node.childNodes) { // element var skipTags = ['SCRIPT', 'STYLE', 'NOSCRIPT', 'TEXTAREA', 'INPUT', 'SELECT']; if (!skipTags.includes(node.tagName)) { Array.from(node.childNodes).forEach(highlight); } } } highlight(document.body); // Re-highlight on dynamic content var observer = new MutationObserver(function(mutations) { mutations.forEach(function(m) { m.addedNodes.forEach(function(node) { if (node.nodeType === 1 || node.nodeType === 3) highlight(node); }); }); }); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:Highlight Search Terms]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ' Enable ruff B015 to catch silent no-op comparisons in tests by shahar1 · Pull Request #66977 · apache/airflow · GitHub
Skip to content

Enable ruff B015 to catch silent no-op comparisons in tests - #66977

Merged
shahar1 merged 5 commits into
apache:mainfrom
shahar1:enable-ruff-b015-useless-comparison
May 16, 2026
Merged

Enable ruff B015 to catch silent no-op comparisons in tests#66977
shahar1 merged 5 commits into
apache:mainfrom
shahar1:enable-ruff-b015-useless-comparison

Conversation

@shahar1

@shahar1shahar1 commented May 15, 2026

Copy link
Copy Markdown
Contributor

Bare actual == expected expressions in tests silently evaluate and discard their result — the test passes regardless of correctness. This is exactly what happened in #66894 (four test_serialize methods in the Vertex AI triggers had been vacuously passing for years).

Changes

  • pyproject.toml: add B015 (useless-comparison) to extend-select. This rule fires on any bare comparison expression used as a statement.
  • 16 test files: add the missing assert to all 26 existing violations found by the rule across airflow-core, task-sdk, and providers amazon, cncf/kubernetes, google).

With this in place, any future bare comparison in a test is a lint error caught before CI runs.


Was generative AI tooling used to co-author this PR?
  • Yes — Claude Code (Sonnet 4.6)

Generated-by: Claude Code (Sonnet 4.6) following the guidelines

@boring-cyborgboring-cyborgBot added area:CLI area:DAG-processing area:providers area:Scheduler including HA (high availability) scheduler area:task-sdk provider:amazon AWS/Amazon - related issues provider:cncf-kubernetes Kubernetes (k8s) provider related issues provider:google Google (including GCP) related issues labels May 15, 2026
Bare `actual == expected` expressions (missing `assert`) silently pass
regardless of correctness. Enable ruff rule B015 (useless-comparison)
to make this a lint error, and add `assert` to all 26 existing instances
found across airflow-core, task-sdk, and providers (amazon, cncf, google).
@shahar1
shahar1force-pushed the enable-ruff-b015-useless-comparison branch from ff2e36f to 7dfec04CompareMay 15, 2026 05:01
@shahar1
shahar1 requested review from Lee-W and jason810496May 15, 2026 05:20
@shahar1
shahar1 marked this pull request as draft May 15, 2026 05:36
`.calls` is not a real MagicMock attribute; accessing it auto-creates a
child MagicMock. The expression `mock.calls[0] == []` was a silent no-op
that B015 correctly caught. Adding `assert` exposed that the comparison
always evaluates to False.
Replace with `assert_not_called()`, which correctly verifies that
`revoke_task` routes through `kube_scheduler.patch_pod_revoked()` rather
than calling `patch_namespaced_pod` directly.
@shahar1
shahar1 marked this pull request as ready for review May 15, 2026 05:50
@shahar1
shahar1 marked this pull request as draft May 15, 2026 06:29
- test_bedrock: set ensure_unique_job_name on the operator before execute
so the not-ensure-unique parametrize cases actually test the right path,
and use pytest.raises for the cases where a conflict error is expected
- test_emr_serverless (create): remove dead get_application mock setup and
wrong call-count assertion; the operator uses waiters, not direct polling
- test_emr_serverless (start job): correct expected call_count from 2 to 1;
the operator calls get_application once (state CREATED is in SUCCESS_STATES
so no retry loop)
@shahar1
shahar1 marked this pull request as ready for review May 15, 2026 06:37

@jscheffljscheffl left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Cool! I assume you can work on making CI green in parallel :-D

- Add missing `assert` to three bare comparisons caught by the new
B015 rule: test_pod_template_file.py, test_otel_logger.py (×2)
- Fix the MappedOperator task_type assertion in test_dag_serialization:
`type(task).__name__` gives the wrapper class (`DecoratedMappedOperator`)
but `operator_class["task_type"]` stores the underlying operator's name
(`task.operator_class.__name__`, e.g. `_PythonDecoratedOperator`)
@shahar1
shahar1 requested a review from potiuk as a code ownerMay 15, 2026 15:55
@shahar1
shahar1 requested a review from bugraoz93 as a code ownerMay 15, 2026 15:55
The operator uses json.dump() which writes strings incrementally to the
file handle; the previous assertion expected bytes in a single write call.
Also adds the missing mock_file.write.reset_mock() between the CSV and
JSON sub-tests so write calls don't accumulate across sections.
@shahar1
shahar1 merged commit 2ed6805 into apache:mainMay 16, 2026
292 checks passed
@shahar1
shahar1 deleted the enable-ruff-b015-useless-comparison branch May 16, 2026 05:24
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:CLIarea:DAG-processingarea:providersarea:Schedulerincluding HA (high availability) schedulerarea:task-sdkprovider:amazonAWS/Amazon - related issuesprovider:cncf-kubernetesKubernetes (k8s) provider related issuesprovider:googleGoogle (including GCP) related issues

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

@shahar1@Lee-W@jscheffl
, 'i'); if (__m === '*' || __re.test(location.href)) { // Strip utm_, fbclid, gclid, etc. from all links on page (function() { var trackingParams = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content', 'fbclid', 'gclid', 'dclid', 'msclkid', 'yclid', 'ref', 'ref_src', 'source', 'medium', 'campaign']; function cleanUrl(url) { try { var u = new URL(url, window.location.origin); var changed = false; trackingParams.forEach(function(p) { if (u.searchParams.has(p)) { u.searchParams.delete(p); changed = true; } }); return changed ? u.toString() : url; } catch (e) { return url; } } function cleanLinks() { document.querySelectorAll('a[href]').forEach(function(a) { var clean = cleanUrl(a.href); if (clean !== a.href) a.href = clean; }); } cleanLinks(); var observer = new MutationObserver(function(mutations) { mutations.forEach(function(m) { m.addedNodes.forEach(function(node) { if (node.nodeType === 1) { if (node.tagName === 'A') cleanLinks(); node.querySelectorAll('a[href]').forEach(function(a) { var clean = cleanUrl(a.href); if (clean !== a.href) a.href = clean; }); } }); }); }); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:Remove Tracking Parameters from Links]', __e); } })(); (function(){ try { var __m = "youtube.com"; var __re = new RegExp('^' + "youtube\\.com" + ' Enable ruff B015 to catch silent no-op comparisons in tests by shahar1 · Pull Request #66977 · apache/airflow · GitHub
Skip to content

Enable ruff B015 to catch silent no-op comparisons in tests - #66977

Merged
shahar1 merged 5 commits into
apache:mainfrom
shahar1:enable-ruff-b015-useless-comparison
May 16, 2026
Merged

Enable ruff B015 to catch silent no-op comparisons in tests#66977
shahar1 merged 5 commits into
apache:mainfrom
shahar1:enable-ruff-b015-useless-comparison

Conversation

@shahar1

@shahar1shahar1 commented May 15, 2026

Copy link
Copy Markdown
Contributor

Bare actual == expected expressions in tests silently evaluate and discard their result — the test passes regardless of correctness. This is exactly what happened in #66894 (four test_serialize methods in the Vertex AI triggers had been vacuously passing for years).

Changes

  • pyproject.toml: add B015 (useless-comparison) to extend-select. This rule fires on any bare comparison expression used as a statement.
  • 16 test files: add the missing assert to all 26 existing violations found by the rule across airflow-core, task-sdk, and providers amazon, cncf/kubernetes, google).

With this in place, any future bare comparison in a test is a lint error caught before CI runs.


Was generative AI tooling used to co-author this PR?
  • Yes — Claude Code (Sonnet 4.6)

Generated-by: Claude Code (Sonnet 4.6) following the guidelines

@boring-cyborgboring-cyborgBot added area:CLI area:DAG-processing area:providers area:Scheduler including HA (high availability) scheduler area:task-sdk provider:amazon AWS/Amazon - related issues provider:cncf-kubernetes Kubernetes (k8s) provider related issues provider:google Google (including GCP) related issues labels May 15, 2026
Bare `actual == expected` expressions (missing `assert`) silently pass
regardless of correctness. Enable ruff rule B015 (useless-comparison)
to make this a lint error, and add `assert` to all 26 existing instances
found across airflow-core, task-sdk, and providers (amazon, cncf, google).
@shahar1
shahar1force-pushed the enable-ruff-b015-useless-comparison branch from ff2e36f to 7dfec04CompareMay 15, 2026 05:01
@shahar1
shahar1 requested review from Lee-W and jason810496May 15, 2026 05:20
@shahar1
shahar1 marked this pull request as draft May 15, 2026 05:36
`.calls` is not a real MagicMock attribute; accessing it auto-creates a
child MagicMock. The expression `mock.calls[0] == []` was a silent no-op
that B015 correctly caught. Adding `assert` exposed that the comparison
always evaluates to False.
Replace with `assert_not_called()`, which correctly verifies that
`revoke_task` routes through `kube_scheduler.patch_pod_revoked()` rather
than calling `patch_namespaced_pod` directly.
@shahar1
shahar1 marked this pull request as ready for review May 15, 2026 05:50
@shahar1
shahar1 marked this pull request as draft May 15, 2026 06:29
- test_bedrock: set ensure_unique_job_name on the operator before execute
so the not-ensure-unique parametrize cases actually test the right path,
and use pytest.raises for the cases where a conflict error is expected
- test_emr_serverless (create): remove dead get_application mock setup and
wrong call-count assertion; the operator uses waiters, not direct polling
- test_emr_serverless (start job): correct expected call_count from 2 to 1;
the operator calls get_application once (state CREATED is in SUCCESS_STATES
so no retry loop)
@shahar1
shahar1 marked this pull request as ready for review May 15, 2026 06:37

@jscheffljscheffl left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Cool! I assume you can work on making CI green in parallel :-D

- Add missing `assert` to three bare comparisons caught by the new
B015 rule: test_pod_template_file.py, test_otel_logger.py (×2)
- Fix the MappedOperator task_type assertion in test_dag_serialization:
`type(task).__name__` gives the wrapper class (`DecoratedMappedOperator`)
but `operator_class["task_type"]` stores the underlying operator's name
(`task.operator_class.__name__`, e.g. `_PythonDecoratedOperator`)
@shahar1
shahar1 requested a review from potiuk as a code ownerMay 15, 2026 15:55
@shahar1
shahar1 requested a review from bugraoz93 as a code ownerMay 15, 2026 15:55
The operator uses json.dump() which writes strings incrementally to the
file handle; the previous assertion expected bytes in a single write call.
Also adds the missing mock_file.write.reset_mock() between the CSV and
JSON sub-tests so write calls don't accumulate across sections.
@shahar1
shahar1 merged commit 2ed6805 into apache:mainMay 16, 2026
292 checks passed
@shahar1
shahar1 deleted the enable-ruff-b015-useless-comparison branch May 16, 2026 05:24
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:CLIarea:DAG-processingarea:providersarea:Schedulerincluding HA (high availability) schedulerarea:task-sdkprovider:amazonAWS/Amazon - related issuesprovider:cncf-kubernetesKubernetes (k8s) provider related issuesprovider:googleGoogle (including GCP) related issues

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

@shahar1@Lee-W@jscheffl
, 'i'); if (__m === '*' || __re.test(location.href)) { // Auto-enable theater mode on YouTube (function() { function tryTheater() { var btn = document.querySelector('button[aria-label="Theater mode"], ytd-player #player button[title="Theater mode"]'); if (btn && !btn.classList.contains('activated')) { btn.click(); } } // Try immediately tryTheater(); // Try after navigation (SPA) var lastUrl = location.href; setInterval(function() { if (location.href !== lastUrl) { lastUrl = location.href; setTimeout(tryTheater, 500); } }, 1000); // Also try on player load var observer = new MutationObserver(tryTheater); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:YouTube Theater Mode Default]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ' Enable ruff B015 to catch silent no-op comparisons in tests by shahar1 · Pull Request #66977 · apache/airflow · GitHub
Skip to content

Enable ruff B015 to catch silent no-op comparisons in tests - #66977

Merged
shahar1 merged 5 commits into
apache:mainfrom
shahar1:enable-ruff-b015-useless-comparison
May 16, 2026
Merged

Enable ruff B015 to catch silent no-op comparisons in tests#66977
shahar1 merged 5 commits into
apache:mainfrom
shahar1:enable-ruff-b015-useless-comparison

Conversation

@shahar1

@shahar1shahar1 commented May 15, 2026

Copy link
Copy Markdown
Contributor

Bare actual == expected expressions in tests silently evaluate and discard their result — the test passes regardless of correctness. This is exactly what happened in #66894 (four test_serialize methods in the Vertex AI triggers had been vacuously passing for years).

Changes

  • pyproject.toml: add B015 (useless-comparison) to extend-select. This rule fires on any bare comparison expression used as a statement.
  • 16 test files: add the missing assert to all 26 existing violations found by the rule across airflow-core, task-sdk, and providers amazon, cncf/kubernetes, google).

With this in place, any future bare comparison in a test is a lint error caught before CI runs.


Was generative AI tooling used to co-author this PR?
  • Yes — Claude Code (Sonnet 4.6)

Generated-by: Claude Code (Sonnet 4.6) following the guidelines

@boring-cyborgboring-cyborgBot added area:CLI area:DAG-processing area:providers area:Scheduler including HA (high availability) scheduler area:task-sdk provider:amazon AWS/Amazon - related issues provider:cncf-kubernetes Kubernetes (k8s) provider related issues provider:google Google (including GCP) related issues labels May 15, 2026
Bare `actual == expected` expressions (missing `assert`) silently pass
regardless of correctness. Enable ruff rule B015 (useless-comparison)
to make this a lint error, and add `assert` to all 26 existing instances
found across airflow-core, task-sdk, and providers (amazon, cncf, google).
@shahar1
shahar1force-pushed the enable-ruff-b015-useless-comparison branch from ff2e36f to 7dfec04CompareMay 15, 2026 05:01
@shahar1
shahar1 requested review from Lee-W and jason810496May 15, 2026 05:20
@shahar1
shahar1 marked this pull request as draft May 15, 2026 05:36
`.calls` is not a real MagicMock attribute; accessing it auto-creates a
child MagicMock. The expression `mock.calls[0] == []` was a silent no-op
that B015 correctly caught. Adding `assert` exposed that the comparison
always evaluates to False.
Replace with `assert_not_called()`, which correctly verifies that
`revoke_task` routes through `kube_scheduler.patch_pod_revoked()` rather
than calling `patch_namespaced_pod` directly.
@shahar1
shahar1 marked this pull request as ready for review May 15, 2026 05:50
@shahar1
shahar1 marked this pull request as draft May 15, 2026 06:29
- test_bedrock: set ensure_unique_job_name on the operator before execute
so the not-ensure-unique parametrize cases actually test the right path,
and use pytest.raises for the cases where a conflict error is expected
- test_emr_serverless (create): remove dead get_application mock setup and
wrong call-count assertion; the operator uses waiters, not direct polling
- test_emr_serverless (start job): correct expected call_count from 2 to 1;
the operator calls get_application once (state CREATED is in SUCCESS_STATES
so no retry loop)
@shahar1
shahar1 marked this pull request as ready for review May 15, 2026 06:37

@jscheffljscheffl left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Cool! I assume you can work on making CI green in parallel :-D

- Add missing `assert` to three bare comparisons caught by the new
B015 rule: test_pod_template_file.py, test_otel_logger.py (×2)
- Fix the MappedOperator task_type assertion in test_dag_serialization:
`type(task).__name__` gives the wrapper class (`DecoratedMappedOperator`)
but `operator_class["task_type"]` stores the underlying operator's name
(`task.operator_class.__name__`, e.g. `_PythonDecoratedOperator`)
@shahar1
shahar1 requested a review from potiuk as a code ownerMay 15, 2026 15:55
@shahar1
shahar1 requested a review from bugraoz93 as a code ownerMay 15, 2026 15:55
The operator uses json.dump() which writes strings incrementally to the
file handle; the previous assertion expected bytes in a single write call.
Also adds the missing mock_file.write.reset_mock() between the CSV and
JSON sub-tests so write calls don't accumulate across sections.
@shahar1
shahar1 merged commit 2ed6805 into apache:mainMay 16, 2026
292 checks passed
@shahar1
shahar1 deleted the enable-ruff-b015-useless-comparison branch May 16, 2026 05:24
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:CLIarea:DAG-processingarea:providersarea:Schedulerincluding HA (high availability) schedulerarea:task-sdkprovider:amazonAWS/Amazon - related issuesprovider:cncf-kubernetesKubernetes (k8s) provider related issuesprovider:googleGoogle (including GCP) related issues

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

@shahar1@Lee-W@jscheffl
, 'i'); if (__m === '*' || __re.test(location.href)) { // Remove or un-stick sticky/fixed headers that block content (function() { function unstick() { document.querySelectorAll('header, nav, [role="banner"], .header, .navbar, .sticky, .fixed-top, [style*="position: fixed"], [style*="position:sticky"]').forEach(function(el) { if (el.style.position === 'fixed' || el.style.position === 'sticky' || getComputedStyle(el).position === 'fixed' || getComputedStyle(el).position === 'sticky') { el.style.position = 'static'; el.style.top = 'auto'; el.style.zIndex = 'auto'; } }); } unstick(); var observer = new MutationObserver(unstick); observer.observe(document.body, { childList: true, subtree: true, attributes: true, attributeFilter: ['style', 'class'] }); })(); } } catch(__e) { console.warn('[Userscript:Kill Sticky Headers]', __e); } })(); })(); Enable ruff B015 to catch silent no-op comparisons in tests by shahar1 · Pull Request #66977 · apache/airflow · GitHub
Skip to content

Enable ruff B015 to catch silent no-op comparisons in tests - #66977

Merged
shahar1 merged 5 commits into
apache:mainfrom
shahar1:enable-ruff-b015-useless-comparison
May 16, 2026
Merged

Enable ruff B015 to catch silent no-op comparisons in tests#66977
shahar1 merged 5 commits into
apache:mainfrom
shahar1:enable-ruff-b015-useless-comparison

Conversation

@shahar1

@shahar1shahar1 commented May 15, 2026

Copy link
Copy Markdown
Contributor

Bare actual == expected expressions in tests silently evaluate and discard their result — the test passes regardless of correctness. This is exactly what happened in #66894 (four test_serialize methods in the Vertex AI triggers had been vacuously passing for years).

Changes

  • pyproject.toml: add B015 (useless-comparison) to extend-select. This rule fires on any bare comparison expression used as a statement.
  • 16 test files: add the missing assert to all 26 existing violations found by the rule across airflow-core, task-sdk, and providers amazon, cncf/kubernetes, google).

With this in place, any future bare comparison in a test is a lint error caught before CI runs.


Was generative AI tooling used to co-author this PR?
  • Yes — Claude Code (Sonnet 4.6)

Generated-by: Claude Code (Sonnet 4.6) following the guidelines

@boring-cyborgboring-cyborgBot added area:CLI area:DAG-processing area:providers area:Scheduler including HA (high availability) scheduler area:task-sdk provider:amazon AWS/Amazon - related issues provider:cncf-kubernetes Kubernetes (k8s) provider related issues provider:google Google (including GCP) related issues labels May 15, 2026
Bare `actual == expected` expressions (missing `assert`) silently pass
regardless of correctness. Enable ruff rule B015 (useless-comparison)
to make this a lint error, and add `assert` to all 26 existing instances
found across airflow-core, task-sdk, and providers (amazon, cncf, google).
@shahar1
shahar1force-pushed the enable-ruff-b015-useless-comparison branch from ff2e36f to 7dfec04CompareMay 15, 2026 05:01
@shahar1
shahar1 requested review from Lee-W and jason810496May 15, 2026 05:20
@shahar1
shahar1 marked this pull request as draft May 15, 2026 05:36
`.calls` is not a real MagicMock attribute; accessing it auto-creates a
child MagicMock. The expression `mock.calls[0] == []` was a silent no-op
that B015 correctly caught. Adding `assert` exposed that the comparison
always evaluates to False.
Replace with `assert_not_called()`, which correctly verifies that
`revoke_task` routes through `kube_scheduler.patch_pod_revoked()` rather
than calling `patch_namespaced_pod` directly.
@shahar1
shahar1 marked this pull request as ready for review May 15, 2026 05:50
@shahar1
shahar1 marked this pull request as draft May 15, 2026 06:29
- test_bedrock: set ensure_unique_job_name on the operator before execute
so the not-ensure-unique parametrize cases actually test the right path,
and use pytest.raises for the cases where a conflict error is expected
- test_emr_serverless (create): remove dead get_application mock setup and
wrong call-count assertion; the operator uses waiters, not direct polling
- test_emr_serverless (start job): correct expected call_count from 2 to 1;
the operator calls get_application once (state CREATED is in SUCCESS_STATES
so no retry loop)
@shahar1
shahar1 marked this pull request as ready for review May 15, 2026 06:37

@jscheffljscheffl left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Cool! I assume you can work on making CI green in parallel :-D

- Add missing `assert` to three bare comparisons caught by the new
B015 rule: test_pod_template_file.py, test_otel_logger.py (×2)
- Fix the MappedOperator task_type assertion in test_dag_serialization:
`type(task).__name__` gives the wrapper class (`DecoratedMappedOperator`)
but `operator_class["task_type"]` stores the underlying operator's name
(`task.operator_class.__name__`, e.g. `_PythonDecoratedOperator`)
@shahar1
shahar1 requested a review from potiuk as a code ownerMay 15, 2026 15:55
@shahar1
shahar1 requested a review from bugraoz93 as a code ownerMay 15, 2026 15:55
The operator uses json.dump() which writes strings incrementally to the
file handle; the previous assertion expected bytes in a single write call.
Also adds the missing mock_file.write.reset_mock() between the CSV and
JSON sub-tests so write calls don't accumulate across sections.
@shahar1
shahar1 merged commit 2ed6805 into apache:mainMay 16, 2026
292 checks passed
@shahar1
shahar1 deleted the enable-ruff-b015-useless-comparison branch May 16, 2026 05:24
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:CLIarea:DAG-processingarea:providersarea:Schedulerincluding HA (high availability) schedulerarea:task-sdkprovider:amazonAWS/Amazon - related issuesprovider:cncf-kubernetesKubernetes (k8s) provider related issuesprovider:googleGoogle (including GCP) related issues

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

@shahar1@Lee-W@jscheffl