Skip to content
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

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

Open
AbdAlRahman-Odeh-99 opened this issue Oct 22, 2022 · 1 comment
Open

Comments

@AbdAlRahman-Odeh-99
Copy link

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)
@abhinab-choudhury
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants