Skip to content

Move internet tests in single file #3579

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

Merged
merged 4 commits into from
Mar 17, 2021

Conversation

NicolasHug
Copy link
Member

This PR moves all internet-related tests in a single file. This will make ignoring these tests easier on fb internals.

To make sure I didn't miss any tests, I used https://github.com/miketheman/pytest-socket to disable all internet access, and ported those that failed

@NicolasHug
Copy link
Member Author

There are still 3 tests that I need to port: those that use get_test_images https://github.com/pytorch/vision/blob/master/test/test_onnx.py#L386.

Naively porting these tests would require importing their base class ONNXExporterTester into the new test_internet.py file, to avoid too much code duplication. Unfortunately, importing ONNXExporterTester in a new test file means that pytest will run all of the ONNXExporterTester tests in the new file, which is not desired.

I would suggest to just download the 2 test images and put them in the assets directory instead, so that these tests don't even make any internet call.

Alternatively, I can extract the ONNXExporterTester.run_model (and others) methods in a new common file.

Thoughts @fmassa @pmeier?

@codecov
Copy link

codecov bot commented Mar 17, 2021

Codecov Report

Merging #3579 (fac95ec) into master (bb2805a) will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##           master    #3579   +/-   ##
=======================================
  Coverage   79.07%   79.07%           
=======================================
  Files         105      105           
  Lines        9787     9787           
  Branches     1572     1572           
=======================================
  Hits         7739     7739           
  Misses       1567     1567           
  Partials      481      481           

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update bb2805a...fac95ec. Read the comment docs.

Copy link
Collaborator

@pmeier pmeier left a comment

Choose a reason for hiding this comment

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

  1. Just FYI: Everything in test/test_datasets_download.py also requires internet connection, but these tests are already ignored in our normal runs
    pytest --cov=torchvision --junitxml=test-results/junit.xml -v --durations 20 test --ignore=test/test_datasets_download.py
  2. Although I like the idea behind this change, I think it is problematic that these tests are now grouped by requirements. If we could depend on pytest we could simply use @pytest.mark.internet marker on these tests and add a --skip-internet command line option. This can be done without any additional plugins. For context, I also use @pytest.mark.slow for slow tests (runtime > 1 s) to be able to run a large portion of the test suite significantly faster.

Copy link
Member

@fmassa fmassa left a comment

Choose a reason for hiding this comment

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

PR looks good, thanks!

About ONNX tests: they are only run on OSS, so we can leave them as is.

Comment on lines 78 to 99
@unittest.skipIf(_HAS_VIDEO_OPT is False, "Didn't compile with ffmpeg")
@PY39_SKIP
class VideoAPITester(unittest.TestCase):

VIDEO_DIR = os.path.join(os.path.dirname(os.path.abspath(__file__)), "assets", "videos")

def _fate(self, name, path="."):
"""Download and return a path to a sample from the FFmpeg test suite.
See the `FFmpeg Automated Test Environment <https://www.ffmpeg.org/fate.html>`_
"""

file_name = name.split("/")[1]
utils.download_url("http://fate.ffmpeg.org/fate-suite/" + name, path, file_name)
return os.path.join(path, file_name)

def test_fate_suite(self):
video_path = self._fate("sub/MovText_capability_tester.mp4", self.VIDEO_DIR)
vr = VideoReader(video_path)
metadata = vr.get_metadata()

self.assertTrue(metadata["subtitles"]["duration"] is not None)
os.remove(video_path)
Copy link
Member

Choose a reason for hiding this comment

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

Let's leave this test where it was before. We currently don't run those tests in FB, and I'm unsure about the license for those videos. cc @bjuncek

@fmassa
Copy link
Member

fmassa commented Mar 17, 2021

@pmeier skipped tests don't play well with our internal infra, so using markers wouldn't work.

And we don't run test_dataset_downloads.py internally, so it's fine to keep it as is.

Copy link
Member

@fmassa fmassa left a comment

Choose a reason for hiding this comment

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

Thanks!

@fmassa fmassa merged commit 8ee6339 into pytorch:master Mar 17, 2021
facebook-github-bot pushed a commit that referenced this pull request Mar 19, 2021
Summary:
* Put internet tests in single file

* adding the file

* edit contirbuting guide

* restore videoapi test

Reviewed By: fmassa

Differential Revision: D27127990

fbshipit-source-id: bb68aba1c422d31f158390d963e683116ca35858
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants