-
Notifications
You must be signed in to change notification settings - Fork 253
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
Refactor tests #214
Refactor tests #214
Conversation
utils is now a fixture providing tmp_path to run cibuildwheel
Looks ok, but I'm terrified of next rebase of c++11 on macOS PR #156 |
@Czaki, |
Maybe add def build_dir(self):
return str(tmp_path) I do not have any use case for this in this moment, but I strongly expect such interface. |
I was thinking about this but, as you said, there's no use case yet. When it arises, it can be easily added. |
It may be useful during debug. But not in final form of test. |
Hi guys! I'm not exactly a pytest pro and I'm not sure how this is different/the same from what we had before. Maybe it's easier to start with - what's the motivation behind these changes? |
Why create custom fixture should write @mayeut. |
Hi there :) Just commented on #213 as well.
Thanks! We can take the best parts of the two PRs and make an even better one :)
Hmm, I quite like how this hides the dependency on the temporary directory like this! :-) Less typing and less cluttering.
Could you explain which filenames were clashing? Because I liked the fact before that you could copy a template directory before and only needed change the name of the folder. The less test-specific names, the better, no?
OK, that's pretty cool! If anyone still doubted this was necessary, ... :-) |
Clashing names are |
Ha, and |
pytest can distinguish base on folder if folder contains |
test/conftest.py
Outdated
Uses the current Python interpreter. | ||
Configure settings using env. | ||
''' | ||
if env is None: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this env
ever used?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that It is needed in test which check that CIBW fail to start if no CI variable is set and CIBW_PLATFORM
is not set.
There is no such test now but I think that it should be created.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is done automatically by just running cibuildwheel
, and test 01_basic
also tests it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No. Current version of cibuildwheel
check on begin if it is running on some of CI or if CIBW_PLATFORM
is set. But someone can suggest change which omit this check.
Only possible option for check this in test is to unset some of environment variable. Otherwise after some change it may happen that launching tests will do some changes in host system. Something like:
def test_platoform(utils):
# check if cibuildwheel fail if runing without CIBW_PATFORM outside CI
env = os.environ.copy()
if "CIBW_PLATFORM" in env:
del env["CIBW_PLATFORM"]
if "CI" in env:
del env["CI"]
if "BITRISE_BUILD_NUMBER" in env:
del env["BITRISE_BUILD_NUMBER"]
if "AZURE_HTTP_USER_AGENT" in env:
del env["AZURE_HTTP_USER_AGENT"]
with pytest.raises(subprocess.CalledProcessError)
utils.cibuildwheel_run()
ce3dae6
to
efeff7c
Compare
I thought that to from a bug report but unfortunately it's not working... |
@@ -66,6 +66,7 @@ def main(): | |||
platform = args.platform | |||
else: | |||
ci = strtobool(os.environ.get('CI', 'false')) or 'BITRISE_BUILD_NUMBER' in os.environ or 'AZURE_HTTP_USER_AGENT' in os.environ | |||
platform = None |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was a bug introduced in a previous PR of mine. The error message a few lines below doesn't get triggered, instead we get a platform is being used before assignment
kind of message.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A test shall probably be added for this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
here is my suggestion for base
def test_platoform(utils):
# check if cibuildwheel fail if runing without CIBW_PATFORM outside CI
env = os.environ.copy()
if "CIBW_PLATFORM" in env:
del env["CIBW_PLATFORM"]
if "CI" in env:
del env["CI"]
if "BITRISE_BUILD_NUMBER" in env:
del env["BITRISE_BUILD_NUMBER"]
if "AZURE_HTTP_USER_AGENT" in env:
del env["AZURE_HTTP_USER_AGENT"]
with pytest.raises(subprocess.CalledProcessError)
utils.cibuildwheel_run()
checking output can be done in way showed here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's not the focus of this PR, though?
Although, yeah, now that a refactoring is being done.
Is this so crucial to test, though?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Given the various comments about running tests or cibuildwheel
itself unadvertently on a dev machine, I'd say it's crucial to test.
My comment "A test shall probably be added for this" is more of a self reminder to create another PR for this. Probably a unit test (which allows for more finer grained things without having to parse output) rather than an integration test.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmmm, myes, OK
Ok so not only the folder has to contain A new test can now be added with a simple copy/paste of an existing one which is a very good thing. |
Sorry guys, I'm not convinced of this PR, it's maybe not a clean win quite yet...! Maybe it's more DRY now, but to my eyes, the code looks to be less simple and obvious. Maybe the following could be improved/resolved? -
Maybe I still don't understand the upside - the material difference I'm seeing so far is built wheels are going to a temp directory which resolves missing cleanup between runs. But to me, this could be resolved with I did take a quick look at #213, which might be closer, but many of the above points would apply to to that too. Happy to hear responses / thoughts on the above! |
Most of the major changes are related to getting As you said yourself
For a Python developer, running Let me try to answer each point:
If we want to get
My feeling is that
Yes, it has a state, if it's just a naming thing, it can be renamed. The fact it has a state allows to simplify each test (but then requires to understand the fixture).
Again, name could be changed to something more obvious
By sticking to a postfix _test I guess you mean |
@joerick, I opened 2 other PR #217 / #218 which are much simpler, without all the fuss around To sum-up
For the first, I do understand your point that it makes the test projects different to the projects that cibuildwheel really builds. It seems that |
Thank you for the detailed explanation @mayeut! this seems to be the crux, as you say
https://docs.pytest.org/en/latest/pythonpath.html#standalone-test-modules-conftest-py-files |
This is great! There's just going on so much in this PR, because @mayeut and @Czaki found a bunch of other things that can be improved (I agree just calling |
closed in favor of #217 |
Similar to #213 but since I started this before it was opened, I finished up what I was doing and this allows to choose a baseline between the 2.
utils
fixture instead of importingutils
.The
utils
fixture itself uses thetmp_path
fixture in order to be able to work in a specific temporary test directory. All calls toutils.cibuildwheel_run
now automatically output wheels in this temporary test directory. Alist_wheels()
function has been added toutils
in order to list the wheels from the correct directory without bothering specifying a path (instead ofos.listdir('wheelhouse')
.-2nd commit: Run tests with direct
pytest
invocationAs mentioned in #213, this required to move things around a bit regarding filenames. Still as mentioned in the other PR, one other solution is to add an
__init__.py
file in each test folder. Yet another solution is to move thecibuildwheel
test drivers directly in thetest
folder.3rd commit: taken from #213, thanks @Czaki
I kept 2 commits for the
utils
fixture and allowingpytest
direct invocation. I think both should be kept (as in #213), it's much more easier/usual to just be able to runpytest
directly.The first commit revealed an issue in one of the test due to lack of isolation.