I have a test that is checking if a function is creating a list of information within an excel file. The function takes an argument of the file where the information will be created.
excelfile = test_files\\Class\\Default_Class_Input.xlsx
localinstance = Class.function(excelfile)
I have provided the relative path to the file within the project as above. Initially this wasn't working until I confirmed the path structure. The test now consistently passes on my local machine.
However, when I uploaded this to Azure Devops the test running indicates the following error:
FileNotFoundError: [Errno 2] No such file or directory: 'test_files\\Class\\Default_Class_Input.xlsx'
I thought this may be because there was no file in the build but I can see the file at that path within the build. There is nothing that has not been committed and pushed to the azuredevops build i.e. there is no difference between my local build and the Azuredevops build.
What am I missing?
I have a test that is checking if a function is creating a list of information within an excel file. The function takes an argument of the file where the information will be created.
excelfile = test_files\\Class\\Default_Class_Input.xlsx
localinstance = Class.function(excelfile)
I have provided the relative path to the file within the project as above. Initially this wasn't working until I confirmed the path structure. The test now consistently passes on my local machine.
However, when I uploaded this to Azure Devops the test running indicates the following error:
FileNotFoundError: [Errno 2] No such file or directory: 'test_files\\Class\\Default_Class_Input.xlsx'
I thought this may be because there was no file in the build but I can see the file at that path within the build. There is nothing that has not been committed and pushed to the azuredevops build i.e. there is no difference between my local build and the Azuredevops build.
What am I missing?
Share Improve this question asked Mar 10 at 15:10 sdaw145sdaw145 413 bronze badges 6- How is the excel file generated? It is generated by the function, or it is always existing as part of the code project and the function just trying to write information into the excel file? @sdaw145 – Bright Ran-MSFT Commented Mar 11 at 2:21
- If the file is definitely there in test_files directory of the repo, then it is likely that the build machine on Azure Devops is under linux and does not recognize backslashes. What if you change the path to os.path.join('test_files', 'Class', 'Default_Class_Input.xlsx')? – Maxim Ivanov Commented Mar 11 at 5:58
- @BrightRan-MSFT it is a pre existing spreadsheet not generated by the function. The function just writes information to the spreadsheet – sdaw145 Commented Mar 12 at 12:35
- @sdaw145, Have you checked if this Excel file has been checked out (or downloaded) to the correct relative path within the pipeline working directory? – Bright Ran-MSFT Commented Mar 13 at 5:30
- @BrightRan-MSFT yes that file is present within azure in the same folder location – sdaw145 Commented Mar 13 at 17:26
1 Answer
Reset to default 0You can try to print the current path location inside the test to see where it's running from.(How do I get the full path of the current file's directory?)
Also i have limited experience with azuredevops test plans however if you run the tests using a pipeline you can use the system variables to specify where you file is at.(https://learn.microsoft/en-us/azure/devops/pipelines/build/variables?view=azure-devops&tabs=yaml)
the variable you want will probably be 'Agent.BuildDirectory'
for one quick fix you can try to change your path to '.\\test_files\\Class\\Default_Class_Input.xlsx'
https://www.lenovo/us/en/glossary/dot-slash/?Ref=https%253A%252F%252Fwww.google%252F
What is the difference between using dot slash and just the file name?
Using just the file name without dot slash relies on the system's path to locate the executable. If the file is in a directory that's in your path, you can call it directly. Dot slash explicitly tells the system to bypass the path and look in the current directory, which is essential if the current directory is not in the path.