-
Notifications
You must be signed in to change notification settings - Fork 264
Test CWD issues discovered in beta #2406
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
Comments
My thought was to check for usage of There are a couple of things still to understand or fix: #2405 and I want to understand what numpy is doing to try to import |
Here's what I was thinking: if build_options.test_sources:
test_cwd = testing_temp_dir / "test_cwd"
container.call(["mkdir", "-p", test_cwd])
copy_test_sources(
build_options.test_sources,
build_options.package_dir,
test_cwd,
copy_into=container.copy_into,
)
elif test_command_prepared != prepare_command(
build_options.test_command,
wheel=wheel_to_test,
):
# Back-compat mode for cibuildwheel < 3
# Run the tests from a different directory
log.warning(
"Using {project} and {package} in test_command is deprecated; triggering back-compat mode for cibuildwheel < 3."
)
test_cwd = testing_temp_dir / "test_cwd"
container.call(["mkdir", "-p", test_cwd])
else:
# There are no test sources. Run the tests in the project directory.
test_cwd = PurePosixPath(container_project_path)
container.call(["sh", "-c", test_command_prepared], cwd=test_cwd, env=virtualenv_env) That would cover:
I'm also fine if we just want to not allow the new project cwd case, and instead have:
One possible option would be to just fix the test-sources problem, and then do another beta release. I'm not sure how common the problem is, as the issue here stems from |
Thanks for this. I want to understand the various failure modes a little better e.g. is the reason that PYTHONSAFEPATH isn't helping just that it only has an effect on 3.11+? My feeling is that the old behaviour doesn't hurt anyone, and was actually helping more than we suspected. I think the backward-compatibility method might work, but-
It also sorta depends on how strongly we want to push |
NumPy and Astropy both already required Python >= 3.11 at the time of testing, so I don't think that explains it. |
The problem is that numpy has Given that you can run the test suite from anywhere, maybe It would be nice to know what the fix is, and how common this setup is. |
New users aren't that big of a problem - users always have to work around this to run their tests locally. Maybe back when "inplace" building was a thing, but now everyone uses editable or wheel builds, and they have to work around it. That's why it was so easy to fix for numpy; the CI tests already used the chdir trick. Users have to do this locally to test numpy. The current method is more of a footgun, IMO. It's unexpected to have to use But I do also want to minimize upgrading issues, so unless we can tell users exactly what can go wrong and how to fix it, we probably should have something for backcompat. We do want people using test-sources so they can more easily add mobile wheels, I think, so maybe forfeiting in-place builds when it's not set is the way to go. |
correct, we also have an |
I've done some research- A project without
|
It feels to me that it's just not worth the change to shift the CWD to the project-dir. The impacts will likely be more than just the This also rules out a backward-compat behaviour keyed on My proposal, then, is to revert back to the v2.0 behaviour when test-sources is unset - cibuildwheel will create a temp dir containing the |
Minor correction - it's in both places, pytest seems to get upset with importing conftest file because it finds it twice. But that error is incidental (fortunate, even!) to the issue that the wrong package was found to when |
BTW, if 1 works everywhere, and 2-4 work on Python 3.11+, it was nearly working as expected. Okay, let's go with 2.x style out of source runs. So then the question becomes, do we want to mimic this in Also, if we revert this, what about the PYTHONSAFEPATH and |
I don't think we need a test-in-source option. If a user really wants to run from the project dir, they can
Hmm. I don't follow. I think we can be a little simpler than what you describe! We don't need 3 different dirs, only two. We have the test_cwd, that's either- a) if test-sources is set, it contains the files specified by test-sources. In this mode, you can do relative path I'll put together a PR to illustrate what I'm thinking.
I'd say we don't need to set I'm +0 on keeping |
The problem is iOS. There, this will run in the test source and using placeholders is not allowed. The old mechanism requires a placeholder in the test command! We can tie this behavior change to test-sources instead. I’d like to know if iOS can support placeholders as long as the path is inside the right directory. If so, having both seems clearer for the user. If not, then just combining them seems fine. |
It doesn't require a placeholder in the test command if test-sources is set, because test-sources brings the test files into the cwd. |
Edited above; I'd like to see if iOS can mimic the current behavior. Would the placeholders still refer to the original paths? I like the idea that it simply changes what is added to the new cwd, and doesn't touch the placeholders at all. (Which is what you described but I was thinking of a different model when I read it, so missed that). |
Yeah, I think we'd just leave That might actually be an opportunity for a nice error message on iOS - if a |
Ya know, this is pretty nice actually. We currently have an error on iOS when you don't define I think we can remove the error on unset test-sources, and just use the |
As noted by @joerick, the complication on iOS will be that the build machine (i.e., the machine starting the test run) won't have any visibility of what the Having The best case I can think of would be replacing
To make sure I'm following correctly - you're suggesting:
That way, on an iOS project with no
1-3 all look like good outcomes; 4 and 5 could be potentially confusing - but I'm not sure there's any good way around those other than documentation, and you'd get those anyway if you had an incorrect Have I understood correctly? |
Yeah, you're right generally speaking, that's what I'm thinking. With the slight correction that (5) would have to be Additionally, (4) and (5) are already invalid configurations on other platforms too - that would be no different on iOS. |
Any feeling on this @henryiii ? I'm tempted to remove it from a YAGNI perspective. |
Which one? |
It seems that in the beta we're seeing a couple instances of the test cwd change causing significant backwards incompatibility-
Even with PYTHONSAFEPATH applied, it seems that there's some behaviour (could be pytest's
prepend
mode?) that is causing issues with import paths in test commands. I haven't looked into it in any depth, but I wanted to make an issue as somewhere to discuss.For what it's worth, I suggested making the change to the test CWD to clean up options specification, as I thought the temp dir wasn't providing us much benefit anyway. It looks like that might not have been 100% right!
I think we still have the option of keeping the temp CWD behaviour when test-sources is unset. One thing to consider is if it's worth just returning to that behaviour. Of course the best thing would be for projects to switch to
/src
for their code, but we know that a cibuildwheel upgrade is unlikely to be enough of a reason to make that (huge) change.The text was updated successfully, but these errors were encountered: