Beginner Question: Specify Input Files in config.yml


#1

Super newbie question - I have a couple of files in the tests project folder - tests/setA/testSetA.py. How do I specify these input files required by my Python script, in the circleci configuration file?

Here’s the configuration file I have at the moment.

# Python CircleCI 2.0 configuration file
#
# Check https://circleci.com/docs/2.0/language-python/ for more details
#
version: 2
jobs:
  build:
    docker:
      # specify the version you desire here
      # use `-browsers` prefix for selenium tests, e.g. `3.6.1-browsers`
      - image: circleci/python:3.6.1
      
      # Specify service dependencies here if necessary
      # CircleCI maintains a library of pre-built images
      # documented at https://circleci.com/docs/2.0/circleci-images/
      # - image: circleci/postgres:9.4

    working_directory: ~/repo

    steps:
      - checkout

      - run:
          name: install dependencies
          command: |
            python3 -m venv venv
            . venv/bin/activate
            pip install -r requirements/requirements.txt

      # run tests!
      - run:
          name: run tests
          command: |
            . venv/bin/activate
            python3 tests/setA/testSetA.py

#      - store_artifacts:
#          path: test-reports
#          destination: test-reports

#2

I would guess this file is available after you’ve checked out, and will be available at tests/setA/testSetA.py or ~/repo/tests/setA/testSetA.py.

I don’t think you’ve said what happens with the config file you have presented?


#3

Hi, Thanks for getting back. The ‘run tests’ phase of the build fails with the below error message:

#!/bin/bash -eo pipefail
. venv/bin/activate
python3 tests/setA/testSetA.py
process: [Errno 2] No such file or directory: 'Table1.csv’
Exited with code 255

Here is the folder structure of my Python project:

Project
|_______Compare
|               |__ compare.py
|               |__ __init__.py
|
|_______tests
                |_____setA
                |           |______Table1.csv
                |           |______Table2.csv
                |           |______testSetA.py  #invokes functions in compare.py 
                |______setB

#4

OK. So, your Python code testSetA.py or a file that calls needs to find a file called Table1.csv. How is that file referenced? May we see the relevant bit of Python code?

(I appreciate you’re a beginner, but if you can learn from my counter-questions, that would be awesome. If you get an error, always put that in the first post, and if your error comes from a piece of code, then show that code as well. That would’ve saved two replies from me, and two replies from you, meaning you get your answer faster!)

Edit

You read my mind - you added the dir structure already. Nice one!


#5

Appreciate your help.

Here’s the code in testSetA.py

import sys
import os

sys.path.append(os.path.abspath(os.path.join(__file__,
                                             os.pardir,
                                             os.pardir,
                                             os.pardir)))

from Compare.compare import *

main('Table1.csv',
     'Table2.csv',
     'ComparisionReport_SetA',
     ',',
     (0,))

#7

yay! Got it to work!


#8

Awesome, what was the answer? I was going to suggest ~repo/tests/setA/Table1.csv, as I don’t know how Python works in terms of relative directory references.


#9

I meant, got the formatting to work. SMH


#10

Ah, gotcha. Try my suggestion above, then. You’d need to add that for both CSV file references.


#11

Would you be able to please post the configuration file with the edit you’ve suggested?


#12

No, I am suggesting a change in testSetA.py. Swap the reference to Table1.csv for the ref I have suggested, and ditto for Table2.csv.


#13

Perfect, the build passed! Yay! Thanks a lot!

Here’s the code if it helps another beginner sometime:

import sys
import os

# Locate Compare package
sys.path.append(os.path.abspath(os.path.join(__file__,
                                             os.pardir,
                                             os.pardir,
                                             os.pardir)))
# Import the functions.
from Compare.compare import *

main(os.path.join(os.path.dirname(__file__), 'Table1.csv'),
     os.path.join(os.path.dirname(__file__), 'Table2.csv'),
     os.path.join(os.path.dirname(__file__), 'ComparisionReport_SetA'),
     ',',
     (0,))

#14

Deploy of possible


#15