 Hello, I am Sergei and this video is part of the debugging Galaxy tutorial in this video. We will talk about fixing a failing unit test So sharing my screen Here is a tutorial. We are heading to section 2 unit test failure So most of Galaxy unit tests are designed to test a separate component or function or method within a class They are supposed to be very fast. They do not require a running Galaxy instance. So they give you instant feedback Finding the issue causing a unit test to fail usually is really simple Heading into the hands-on section Part one finding the failing unit test on github So the first step is to figure out what exactly has gone wrong. What exactly is failing? We need to head over to the Galaxy repository on github and in the branch drop-down menu. We select the training branch So here is the Galaxy Repository on github make sure you are in Galaxy project slash Galaxy and This is the drop-down menu with the branches Dev is the is the default branch. We need to go all the way down And here we'll find the training branch and this is what I'm going to select make sure you don't forget to make this step because The the bugs have been engineered especially for this tutorial and they are obviously available only on the training branch not on the Dev branch Next step Click the red X next to the last commit. You will see a drop-down listing of workflow results And find the unit test slash test parentheses three and so on and click details So red X Next to the last commit the last commit is this one So zero two eb and so on and so forth This is the red X we click the red X We get a list of failed commits. We need the one which says unit tests and so on So on my screen and displays a unit test slash test 3.6 on your screen It might be just unit test slash test and then Dot dot dot it doesn't matter what matters is this is the workflow which failed This is the workflow. We need to look at click details I usually prefer to Right-click and open it in a new tab so that I have the the main list of the failed workflows available I head to the new tab And I didn't scroll down. This is what github does automatically. It scrolls down this long log file or rather log output To the bottom, which is exactly where I want to be And back to the tutorial I have the solution open for some reason This will display a detailed report that includes information about the failed tests try to find the failed test Well, this is going to be straightforward because we see at the very bottom. There are two lines starting with words failed In friendly uppercase letters. So this is one test that failed. This is the other test that failed And here is a summary two test failed and 1974 passed Etc etc Let's make sure we have the right solution. Yes, the log list two failed tests this one on this one Now the first one is the doc test We need the second one because well this Part this section of the tutorial is on unit test failures and the unit test will give you Much more information to That you will use to figure out what exactly went wrong So we need to look at test slash unit slash util Slash test utils dot by and this test strip control characters is the specific test function Which has failed So heading over to part two Running the tests locally So an essential requirement For productive development And for being happy as a developer is a fast feedback loop You want to make a change run a test and immediately get feedback from running your test If you push your edits to the remote fork, if you make a commit and push your commit to the remote fork Whatever you do if you count on running your tests remotely Remotely, uh, you will be sorely disappointed. It will take A very long time time maybe hours to get Feedback and of course, this is highly inefficient Instead, you want to run your tests locally Furthermore, you want to run a specific test that you know is failing not the whole test suite So this is what we're going to do in this part So make sure you are in galaxy root. I'm heading over to my terminal This is my terminal and make sure that i'm that you are in galaxy root I'm indeed in galaxy root just to double check Present working directory is Yes, this is the location of my galaxy root For this tutorial And make sure your virtual environment is activated if activated if not Activated so my virtual environment is not activated You will know that your virtual environment is activated if your command prompt Has a prefix with the name of that virtual environment Mine does not so I need to activate it. The way I do it is by running this command So again dot dot then bin Activate don't forget the leading dot which is the source So dot dot then bin Activate Now I have the prefix now my virtual environment is activated Moving on The simplest way to run the failing test locally is using by test directly So the test is in the failing test is in test slash unit slash util slash test utils So by test Unit util Test util Holding fingers crossed Wonderful it failed which is good because this is what we expected Back to the tutorial. Do you see the error message? Do I see the error message? Absolutely the error message is in bright red color and here it is so assertion error assert bla equals bla but the first one is b space l space a equals bla with no spaces And then we have three lines which clarify this error And again, if you look at the very bottom, you'll get yet another confirmation failed test slash unit slash util slash test utils dot pi name of the test assertion error assert b space l space a equals bla One does not equal the other. So this is the specific error Do you see the error message? Let's let's check the solution Oh, yes So this means that instead of the expected bla we got b space l space a With spaces so far so good three finding and fixing the issue Our next step is to open the test file and see what part of the code base So what module what class and method or standalone function is failing to provide the expected result So the failing test is calling. Huh, let's open the failing test first So the failing test is test unit util. I'm going to open it with my trusted vim editor and The failing test was what was it? test utils and then we are in test utils so the failing test itself was test strip control characters so test strip And of course it is at the very top. It was looking right at me. So let's take a look at it We have a string with a special with a special control character and then We call the strip control characters function, which is located somewhere in the util module So this line line number 21 is the line that's failing. Let's double check the tutorial The failing test is calling the strip control characters function in the util module good That function apparently is not producing the expected output. Let's head over to the util module Where we'll find the function definition So the util module and if you look at line Number six, you'll see that this is where the import happens from galaxy import util So we go to lib galaxy util In it The function we need is strip control characters. So let's look for strip control characters here it is It's a very simple function Let's head back to the tutorial So the failing test is calling the strip control function And here is the function definition So the function takes a string as input And in theory returns a copy of that string with certain characters stripped away It doesn't really matter what characters exactly are stripped away However, from the test we see that the string is modified in a different way Spaces have been added between the characters. Can you see what's causing this behavior? So if we take a close look at the function definition specifically at The last line of the function will see that what it does it takes A delimiter And uses that delimiter to join A list or rather in this case a gen xp a generator expression So what it will do it will take Whatever sequence is produced by the gen xp and join it using this delimiter and the delimiter is a space So that's where the space most likely is coming from Let's double check the tutorial solution The gen xp is evaluated and subsequently joined using a space's delimiter bingo. That's what we thought The space is obviously a typo. We don't want to add anything to the string So the delimiter should be the empty string instead Well, let's fix it I'm going to delete this space. So now I'm joining on the empty string I'm going to write and quit And now I will rerun the pie test and everything passed as expected Heading back to the tutorial Make the change save the file run the same test. Now it should past celebrate. Good finishing up Now you are ready to commit your edits and push the branch to your form. So Heading to the I need to add the modified files I need to get add. So let's see first get status Indeed, I have one modified file. I'm going to add it And I'll just say get at all now my git status Has been changed and now I'm going to commit this change. So get Commit Now pay attention that We need to insert a commit message. Please consult galaxy contributors guide on details On how to write a useful and properly formatted commit message and why it matters in our case. We'll do something simple We'll give it a brief description An imperative description. So what do we do here? We Do not use space as meter Do not use space as a delimiter when Stripping away Characters and we are Done and now you would push your branch to your fork and congratulations This is the end of this section of the debugging galaxy tutorial. You have fixed a failing unit test. Good job