-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
parentwork: In tests, mock all MusicBrainz responses #3332
Comments
This mocking doesn't do anything because `command_output` is never invoked by the code under test. See also #3332.
Hi! I can, but not now as I'm rather occupied these days, and when I will I will probably come back to you as I have no experience with this. If I get it well, the tests test with real Musicbrainz data and it should just request data that we would simulate to separte the network connectivity from the actual code, right? |
Yeah! If you like, you can look around at other tests for MusicBrainz-related stuff that we have that also provides "mock" results from the MB API and asserts that the code processes them correctly. |
Hi! I do have some free time now and I'm trying to get this done. I'm wondering about mocking MB-API outputs: I'm using |
How about mocking |
But when I run the functions and methods in |
That's what the unittest.mock library does for you. There are several ways to do this mocking—check out the docs for details. But the easiest one is probably the Lines 50 to 66 in 0c033bd
|
Ok I will try this out. Thanks! By the way, I made another PR (a draft so far) here: #3557 |
Here is a recent CI failure caused by these networked tests. It would be really great to get this stuff fixed. https://ci.appveyor.com/project/beetbox/beets/builds/33986042/job/gipja1xj6o6948vi |
I tried to look into this. I don't quite understand how |
something like
can I mock the network call made in |
You can mock any function, including those from other libraries. So the trick is basically to find the "lowest-level" function that wraps a network call that you can and produce responses from that. I don't know how to mock one call to a function without mocking all the calls, although it may be possible. However, I think what you want to mock here might be |
Ok that wasn't clear to me. Yes, in this case |
I made the tests work, can you check if it is what you had in mind? |
I didn't notice this when we originally merged the parentwork plugin in #3279, but its tests rely on real communication with the MusicBrainz web service, i.e., they fail if there is no network connectivity. This Travis job is an example of a spurious failure caused by network interruptions.
We need to isolate these tests by mocking the MB queries so that no network traffic is every actually sent.
@dosoe, can you please look into this?
The text was updated successfully, but these errors were encountered: