Repository navigation
Qualify objective() in its own tests, which ROI masks in a suite run - #61
Merged
braverock merged 1 commit intoSep 19, 2026
Merged
Conversation
test-objective-branches.R tests PortfolioAnalytics::objective(). ROI exports a
function of the same name, 27 of the test files attach ROI, and library() does
not move an already-attached package back up the search path. By the time this
file runs in a full suite, objective() is ROI's, which takes a single argument
x, so the tests exercise the wrong function.
Measured, same file, same package build, one library() call apart:
file ROI attached PASS FAIL ERROR
master no 33 0 0
master yes 30 0 2
patched yes 33 0 0
patched no 33 0 0
Error in objective(name = "mean", arguments = list()):
unused arguments (name = "mean", arguments = list())
This is one of the two reasons the run-all.R step fails on master, and the
reason it cannot be reproduced by running the file on its own.
Three calls are qualified. The expected messages are pinned at the same time,
because the first test passed under masking without testing anything: it
matched the regexp "name", and "name" also appears in R's own "unused arguments
(name = NULL, arguments = list())". It now expects the message the function
actually raises.
Nothing in R/ changes.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
There was a problem hiding this comment.
🟢 Approval recommended
The reviewed test changes address the suite-order failure without unresolved issues.
Pull request overview
This PR makes objective branch tests independent of ROI package masking.
Changes:
- Qualifies calls as
PortfolioAnalytics::objective(). - Pins expected error messages.
- Documents the package masking issue.
File summaries
| File | Description |
|---|---|
tests/testthat/test-objective-branches.R |
Ensures objective tests consistently exercise the intended function. |
Review details
- Files reviewed: 1/1 changed files
- Comments generated: 0
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Owner
|
reviewed and merged. Thank you for the contribution to PortfolioAnalytics @sstoeckl ! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
tests/testthat/test-objective-branches.Rpasses when it is run on its own andfails when the suite is run. It is not the package: by the time the file runs,
objective()is a different function.ROIexportsobjective()as well. Twenty-seven of the test files calllibrary(ROI), andlibrary()does not move an already-attached package backup the search path, so a later
library(PortfolioAnalytics)does not restoreit. The tests then call ROI's
objective(), which takes a single argumentx:Measured
Same file, same package build, one
library()call apart:library(ROI)firstmastermasterThe change
Three calls become
PortfolioAnalytics::objective(...), with a comment sayingwhy, so the file tests the function it is written for regardless of what a
previous file attached.
The expected messages are pinned at the same time, because one of the three
tests passed under masking without testing anything: it expected the regexp
"name", andnamealso appears in R's ownunused arguments (name = NULL, arguments = list()). It now expects the sentence the function actually raises.Nothing in
R/changes.Test suite
Run against
master's package code, so the only difference is this file:masterNo errors left. The two failures are the
chart.EfficientFrontierCompare()tests, which #60 fixes; measured there, that file goes from 67 passing
with 2 failures to 69 with none. The two changes touch different files, so
between them the four problems
run-all.Rreports are accounted for.Why this one and #60 are worth taking first
R-CMD-checkandtest-coveragehave both been red onmastersince 24 July,and both die at the same step,
running the tests in 'run-all.R' failed. Whatrun-all.Rreports there is four problems: the two in this file, and two intest-charts-roi.Rthat come from a missing initialisation inchart.EfficientFrontierCompare(). #60 fixes those.With both merged, that step passes and the pipeline is green again. I can only
see that the workflows stop at that step, so if something else is broken behind
it, it is hidden by these four rather than absent.
This matters for the five pull requests that are already open, because their
checks are red for this reason and not for theirs. They do not need rebasing:
the workflows run on
pull_requestandactions/checkout@v4checks out themerge commit, so once
mastercarries these two fixes, re-running the jobs oneach of them is enough.
Scope
One test file, 18 insertions, 5 deletions, of which 12 insertions are the
comment. This change stands on its own.
🤖 Generated with Claude Code