Skip to content
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

Simplify Python test process #10038

Closed
wants to merge 6 commits into from
Closed

Conversation

chadrik
Copy link
Contributor

@chadrik chadrik commented Nov 8, 2019

  • Use pyproject.toml to install requirements for building beam
    • Consolidate a bunch of requirements that were spread across gen_protos, gradle, and tox
    • Remove the convoluted process in gen_protos where it tries to install deps, they're covered by pyproject.toml now
  • Use tox to build sdist of beam instead of gradle: one less virtualenv and fewer deps installed for no reason
  • Remove test_requires because they're already handled by extras
  • Don't call python setup.py nosetests because it rebuilds beam: we want this to be entirely controlled by our tox (our pep517-build system)
  • Stop running tests against code in the source directory! This undermines the sandboxing that tox provides and requires more work from gradle and tox cleanup scripts to try to resolve.

One thing to note here is that despite the progress made by peps 517 and 518 toward improving the python build toolchains, it's still not a turnkey solution. You can't just pip build sdist yet. I tried a dozen different things, but it looks like the best solution is this pep517 module. References:

Another problem is that we're always building cython on linux, rather than doing it conditionally based on the test we're running. Need to figure out if we can control that with environment markers


Thank you for your contribution! Follow this checklist to help us incorporate your contribution quickly and easily:

  • Choose reviewer(s) and mention them in a comment (R: @username).
  • Format the pull request title like [BEAM-XXX] Fixes bug in ApproximateQuantiles, where you replace BEAM-XXX with the appropriate JIRA issue, if applicable. This will automatically link the pull request to the issue.
  • If this contribution is large, please file an Apache Individual Contributor License Agreement.

See the Contributor Guide for more tips on how to make review process smoother.

Post-Commit Tests Status (on master branch)

Lang SDK Apex Dataflow Flink Gearpump Samza Spark
Go Build Status --- --- Build Status --- --- Build Status
Java Build Status Build Status Build Status Build Status
Build Status
Build Status
Build Status Build Status Build Status
Build Status
Python Build Status
Build Status
Build Status
Build Status
--- Build Status
Build Status
Build Status
Build Status
--- --- Build Status
XLang --- --- --- Build Status --- --- ---

Pre-Commit Tests Status (on master branch)

--- Java Python Go Website
Non-portable Build Status Build Status
Build Status
Build Status Build Status
Portable --- Build Status --- ---

See .test-infra/jenkins/README for trigger phrase, status and link of all Jenkins jobs.

@chadrik chadrik force-pushed the simplify-tests branch 3 times, most recently from fb14488 to ac0b3d2 Compare November 9, 2019 21:38
@chadrik
Copy link
Contributor Author

chadrik commented Nov 10, 2019

Run Python PreCommit

@chadrik
Copy link
Contributor Author

chadrik commented Nov 11, 2019

Run Python2_PVR_Flink PreCommit

@chadrik chadrik force-pushed the simplify-tests branch 3 times, most recently from 6f5558b to 2bc357c Compare November 13, 2019 18:29
@chadrik chadrik force-pushed the simplify-tests branch 2 times, most recently from 2128a40 to 491a190 Compare November 25, 2019 07:41
@chadrik chadrik force-pushed the simplify-tests branch 2 times, most recently from 17ec0b1 to a9d4a72 Compare November 25, 2019 07:51
@@ -28,10 +28,10 @@ envname=${1?First argument required: suite base name}
posargs=$2

# Run with pytest-xdist and without.
python setup.py pytest --addopts="-o junit_suite_name=${envname} \
pytest --addopts="-o junit_suite_name=${envname} \
Copy link
Member

Choose a reason for hiding this comment

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

You should be able to remove the --addopts flag and leave the value part.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah yes, I was wrangling with that the other day. It would simplify things if we could just get rid of run_pytest.sh. Do we still need to run the tests with and without xdist?

Copy link
Member

Choose a reason for hiding this comment

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

Yes, there are a few tests that are still incompatible with xdist, such as those using save_main_session.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If the goal is to run both tests regardless of whether there is a failure (i.e. avoid early abort) then you can set the tox setting ignore_errors=true: https://tox.readthedocs.io/en/latest/config.html#conf-ignore_errors

If false, a non-zero exit code from one command will abort execution of commands for that environment. If true, a non-zero exit code from one command will be ignored and further commands will be executed. The overall status will be “commands failed”, i.e. tox will exit non-zero in case any command failed.

I was trying to get run_pytest.sh to work with tox -e py37-pytest -- path/to/test and I was struggling to get the arg passing correct, and ultimately I just moved it to tox.ini and it worked. With ignore_errors=true in place I don't think the shell script will be necessary.

Copy link
Member

Choose a reason for hiding this comment

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

I could try helping with arg passing.

If you specify a certain test to run, one of the pytest runs will certainly fail since it either has or doesn't have the no_xdist marker. The script special-cases the 5 exit status from pytest to handle this scenario.

I'm probably missing something, because the way you set things up tox -e py37-pytest -- path/to/test should have failed (either the -m not no_xdist or the -m no_xdist command should have failed).

In any case, I'm strongly in favor of simplifying the build process by having as few shell scripts as possible.

There's also this plugin to suppress certain exit statuses:
https://github.com/yashtodi94/pytest-custom_exit_code

@chadrik
Copy link
Contributor Author

chadrik commented Nov 27, 2019

Run Python PreCommit

@kennknowles kennknowles changed the title Simplify test process Simplify Python test process Nov 27, 2019
@kennknowles
Copy link
Member

I know it shouldn't be relevant, but I noticed the Java flakes and will file something about them.

@kennknowles
Copy link
Member

run java precommit

@kennknowles
Copy link
Member

Both already had Jiras, so Java precommit is g2g.

setup_requires=['pytest_runner'],
tests_require= [
REQUIRED_TEST_PACKAGES,
INTERACTIVE_BEAM,
Copy link
Member

Choose a reason for hiding this comment

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

I would expect that removing INTERACTIVE_BEAM would cause some tests that depend on these package to fail. I'm guessing there aren't any tests for this yet.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Any tests that require the interactive deps should add the 'interactive' extra. So far I haven't run into any failures related to this.

@chadrik
Copy link
Contributor Author

chadrik commented Nov 27, 2019

Thanks. Slowly chipping away at this. I'll bring this to the list when I have the remaining kinks worked out.

@@ -307,3 +331,10 @@ commands =
coverage report --skip-covered
# Generate report in xml format
coverage xml

[testenv:py37-interactive]
Copy link
Member

Choose a reason for hiding this comment

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

Does this add any additional test coverage? I'd rather fold any 'interactive' tests into the py37 target if possible. Or at least not repeat all the py37 unit tests.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think this addition is actually a rebase error on my part. These tests were not intentionally added by me. IIRC, they were added to tox on master then removed in a later commit, and I must've messed up on one of my rebases and left it in.

@chadrik
Copy link
Contributor Author

chadrik commented Nov 27, 2019

My last two jenkins jobs indicated it took 0s to run, but the logs show that it was aborted after 2 hours. Any idea what could be going on?

@udim
Copy link
Member

udim commented Nov 27, 2019

My last two jenkins jobs indicated it took 0s to run, but the logs show that it was aborted after 2 hours. Any idea what could be going on?

It looks like it hit the 2h Jenkins timeout. Should be extended to 3h once #10234 is merged and the next seed job runs. (I'll start one in #10234)

@@ -226,12 +307,6 @@ def run(self):
]),
install_requires=REQUIRED_PACKAGES,
python_requires=python_requires,
test_suite='nose.collector',
Copy link
Contributor

Choose a reason for hiding this comment

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

What's alternative collector it will use? Can we ensure the collection result unchanged?

Copy link
Member

Choose a reason for hiding this comment

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

I believe it will still use nose, just not via setup.py. We can compare nosetests.xml files to verify.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Correct, test_requires and test_suite are for the python setup.py test and derivative workflows. That whole stack is now deprecated in favor of extras and pep517.

@chadrik
Copy link
Contributor Author

chadrik commented Nov 28, 2019

Run Python PreCommit

@chadrik
Copy link
Contributor Author

chadrik commented Dec 5, 2019

Run Python PreCommit

1 similar comment
@chadrik
Copy link
Contributor Author

chadrik commented Dec 10, 2019

Run Python PreCommit

- Use pyproject.toml and pep517 to install requirements for building beam
- Use tox to build sdist of beam instead of gradle sdist
- Don't call python setup.py nosetests because it rebuilds beam
- Do not run tests on code in the source directory
- Run lint jobs against the source
Tox knows how to do this too, and now that we're using pyproject.toml (pep517 & pep518) we can describe how to do this in a portable way.
WIP:  trying to debug why these are failing
Also, fix a bug where cython coder tests were not actually being run
fix


fix


Fixes
we have to set the pep517 isolated build directory as the site dir for the google .pth file to work and find the nested protobuf package
@stale
Copy link

stale bot commented Mar 17, 2020

This pull request has been marked as stale due to 60 days of inactivity. It will be closed in 1 week if no further activity occurs. If you think that’s incorrect or this pull request requires a review, please simply write any comment. If closed, you can revive the PR at any time and @mention a reviewer or discuss it on the [email protected] list. Thank you for your contributions.

@stale stale bot added the stale label Mar 17, 2020
@stale
Copy link

stale bot commented Mar 24, 2020

This pull request has been closed due to lack of activity. If you think that is incorrect, or the pull request requires review, you can revive the PR at any time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants