luigi icon indicating copy to clipboard operation
luigi copied to clipboard

ImportError: cannot import name 'MockFile' from 'luigi.mock'

Open AbdAlRahman-Odeh-99 opened this issue 3 years ago • 1 comments

Greetings, I have a luigi task that doesn't return any output file, so I want to use MockFile instead to get it done. That being said, it gives me an error when trying to import it. The code:

import luigi
from luigi.mock import MockFile
import subprocess

lass PullImages(luigi.Task):
    task_namespace = 'CMS-Analysis'
    #task_complete = False
    def output(self):
        return MockFile("PullImages", mirror_on_stderr=True)

    def run(self):
        bashCommand = pullCommand()
        process = subprocess.Popen(bashCommand, shell=True, stdout = subprocess.PIPE, stderr = subprocess.PIPE)
        output, error = process.communicate()
        print("The command is: \n",bashCommand)
        print("The output is: \n",output.decode())
        print("Return Code:", process.returncode)
        if process.returncode and error:
            print("The error is: \n",error.decode())
        else:
            self.output().value = True

The error message:

Traceback (most recent call last):
  File "cms-analysis.py", line 2, in <module>
    from luigi.mock import MockFile
ImportError: cannot import name 'MockFile' from 'luigi.mock' (/home/abd/.local/lib/python3.8/site-packages/luigi/mock.py)

AbdAlRahman-Odeh-99 avatar Oct 22 '22 16:10 AbdAlRahman-Odeh-99

Try replacing from luigi.mock import MockFile to from luigi.mock import MockFileSystem

abhinab-choudhury avatar Jun 27 '23 14:06 abhinab-choudhury