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

[BEAM-3713] Add pytest for unit tests #9756

Merged
merged 4 commits into from Nov 4, 2019
Merged

Conversation

udim
Copy link
Member

@udim udim commented Oct 9, 2019

This is #7949 without IT support.

This does not replace regular precommit/postcommit/tox environments.
Pytest will replace nose once we can verify all tests are collected by pytest and blocking bugs are solved (see BEAM-3713).

  • Runs unit tests using pytest
    • tox: tox -e py27-gcp-pytest,py36-pytest,etc.
    • gradle: ../../gradlew pythonPreCommitPytest
    • github PR phrase: run python_pytest precommit
  • Tests run in parallel (still single-threaded but on multiple worker
    processes).
    • no_xdist marker used for tests that don't work the xdist plugin.

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.

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.

@udim
Copy link
Member Author

udim commented Oct 9, 2019

run seed job

1 similar comment
@udim
Copy link
Member Author

udim commented Oct 10, 2019

run seed job

@udim
Copy link
Member Author

udim commented Oct 10, 2019

R: @chadrik

This should be tested with a "run seed job", which should succeed. "run python_pytest precommit" will then launch a pytest-based precommit job (without ITs), but it's not critical that this job passes at this stage.

@chadrik
Copy link
Contributor

chadrik commented Oct 10, 2019

This looks great. What's the plan for deploying it? Do you plan to merge it as is to get it in front of more users for testing, or will you replace nose with pytest before the merge?

@udim
Copy link
Member Author

udim commented Oct 10, 2019 via email

@chadrik
Copy link
Contributor

chadrik commented Oct 10, 2019 via email

@@ -228,6 +229,8 @@ def test_biqquery_read_streaming_fail(self):
r'source is not currently available'):
p.run()

@pytest.mark.skipif(sys.version_info >= (3, 7),
reason='TODO(BEAM-8095): Segfaults in Python 3.7')
Copy link
Contributor

Choose a reason for hiding this comment

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

hmmm... this only segfaults when using pytest? what happens if you disable xdist?

Copy link
Member Author

Choose a reason for hiding this comment

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

I changed it to no_xdist. It still segfaults when using xdist or when attempting to run under a debugger in PyCharm.

Copy link
Contributor

@tvalentyn tvalentyn Oct 23, 2019

Choose a reason for hiding this comment

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

@udim
Copy link
Member Author

udim commented Oct 14, 2019

@chadrik PTAL
CC/R: @markflyhigh, @chamikaramj

Comment on lines 25 to 32
if sys.version_info < (3,):
collect_ignore_glob.append('*_py3.py')
for minor in [5, 6, 7, 8, 9]:
if sys.version_info < (3, minor):
collect_ignore_glob.append('*_py3%d.py' % minor)
Copy link
Contributor

Choose a reason for hiding this comment

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

How about something like this:

MAX_SUPPORTED_PYTHON_VERSION = (3, 8)

# See pytest.ini for main collection rules.
collect_ignore_glob = []
if sys.version_info < (3,):
  collect_ignore_glob.append('*_py3.py')
else:
  for minor in range(sys.version_info.minor +1, MAX_SUPPORTED_PYTHON_VERSION[1] + 1):
    collect_ignore_glob.append('*_py3%d.py' % minor)

Copy link
Contributor

Choose a reason for hiding this comment

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

oh, btw, what did you think of this suggestion?

Copy link
Member Author

Choose a reason for hiding this comment

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

IDK. It's more verbose but I don't have a preference.

Ideally, I'd like a single source of truth for the list of Python supported versions (python_requires in setup.py is such a source but it's hard to parse).

Copy link
Contributor

Choose a reason for hiding this comment

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

IDK. It's more verbose but I don't have a preference.

I think it'll be easier to maintain long term: just update the max support python version.

But maintainability aside, it seems a bit odd to test for our lower bound in a loop when we know precisely what the lower bound is: sys.version_info.minor +1

Ideally, I'd like a single source of truth for the list of Python supported versions (python_requires in setup.py is such a source but it's hard to parse).

true.

Copy link
Member Author

Choose a reason for hiding this comment

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

But maintainability aside, it seems a bit odd to test for our lower bound in a loop when we know precisely what the lower bound is: sys.version_info.minor +1

You're right.

@chadrik
Copy link
Contributor

chadrik commented Oct 21, 2019

I had two thoughts related to this today, as I struggled trying to diagnose some failed tests on jenkins.

  1. it would be great if you could make the gradle tasks run serially, since we're already using xdist to parallelize the work. That will make the logs easier to read since it won't interleave different tox tasks together.
  2. I added a PR to enable color in tox: WIP: tox: allow apps that support color to use it #9840. Hopefully this will work with pytest, because I think it will add a lot of value (unbelievably, nose does not support color out of the box).

@udim
Copy link
Member Author

udim commented Oct 21, 2019

I had two thoughts related to this today, as I struggled trying to diagnose some failed tests on jenkins.

  1. it would be great if you could make the gradle tasks run serially, since we're already using xdist to parallelize the work. That will make the logs easier to read since it won't interleave different tox tasks together.
    Yes that makes sense, the logs already make my browser slow down to a crawl (Reduce the verbosity of local_job_service_main #9813). Let's do that in another PR though.
  1. I added a PR to enable color in tox: WIP: tox: allow apps that support color to use it #9840. Hopefully this will work with pytest, because I think it will add a lot of value (unbelievably, nose does not support color out of the box).

Colors already work for me with tox and pytest. Let's get this PR merged so you can try it out yourself. :)

@chadrik
Copy link
Contributor

chadrik commented Oct 21, 2019

Colors already work for me with tox and pytest.

Great. I've been digging into my problem with colored mypy output problem and I think it's a tty issue. I think mypy needs a mechanism to force colors even when a tty is not present.

it would be great if you could make the gradle tasks run serially, since we're already using xdist to parallelize the work. That will make the logs easier to read since it won't interleave different tox tasks together.

Yes that makes sense, the logs already make my browser slow down to a crawl (#9813). Let's do that in another PR though.

I've also been thinking about investigating using tox's support fo parallel execution instead of gradle: https://tox.readthedocs.io/en/latest/example/basic.html#parallel-mode

Let's get this PR merged so you can try it out yourself. :)

Looks good to me!

This is apache#7949 without IT support.

- Runs unit tests using pytest
  - tox: `tox -e py27-gcp-pytest,py36-pytest,etc.`
  - gradle: `../../gradlew pythonPreCommitPytest`
  - github PR phrase: `run python_pytest precommit`
- Tests run in parallel (still single-threaded but on multiple worker
processes).
  - no_xdist marker used for tests that don't work the xdist plugin.
- Allows specifying test module in tox cmd line. Example:
```sh
tox -e py27-pytest apache_beam.transforms.window_test
```
... instead of completely skipping it for Python 3.7.
@udim
Copy link
Member Author

udim commented Oct 21, 2019

PTAL

@chadrik
Copy link
Contributor

chadrik commented Nov 1, 2019

Looks good. I say we merge this once the tests are confirmed passing.

@udim
Copy link
Member Author

udim commented Nov 1, 2019

Run Java PreCommit

@udim
Copy link
Member Author

udim commented Nov 1, 2019

Run CommunityMetrics PreCommit

@udim
Copy link
Member Author

udim commented Nov 1, 2019

Run Python PreCommit

1 similar comment
@udim
Copy link
Member Author

udim commented Nov 1, 2019

Run Python PreCommit

@udim
Copy link
Member Author

udim commented Nov 4, 2019

Merging since tests pass. Will address BEAM-8095 TODO in a subsequent PR. I believe it has been fixed in #9881.

@udim udim merged commit a6936c8 into apache:master Nov 4, 2019
11moon11 pushed a commit to 11moon11/beam that referenced this pull request Nov 4, 2019
This is apache#7949 without IT support.

- Runs unit tests using pytest
  - tox: `tox -e py27-gcp-pytest,py36-pytest,etc.`
  - gradle: `../../gradlew pythonPreCommitPytest`
  - github PR phrase: `run python_pytest precommit`
- Tests run in parallel (still single-threaded but on multiple worker
processes).
  - no_xdist marker used for tests that don't work the xdist plugin.
- Allows specifying test module in tox cmd line. Example:
```sh
tox -e py27-pytest apache_beam.transforms.window_test
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants