Running llvm-lit on external project test file derived from standalone fails

Is it possible to use llvm-lit to test a single file from an external project (created from examples/standalone)?

For instance, this is possible:

/working_dir/builds/llvm-project/build/bin/llvm-lit /working_dir/llvm-project/mlir/test/Dialect/Linalg/tile-conv.mlir 
-- Testing: 1 tests, 1 workers --
PASS: MLIR :: Dialect/Linalg/tile-conv.mlir (1 of 1)

Testing Time: 0.03s
  Passed: 1

But calling it on an external file returns the following error in this line:

/working_dir/builds/llvm-project/build/bin/llvm-lit /working_dir/standalone/test/Conversion/TensorToLLVM/tensor-to-llvm.mlir
llvm-lit: /working_dir/llvm-project/llvm/utils/lit/lit/TestingConfig.py:140: fatal: unable to parse config file '/working_dir/standalone/test/lit.cfg.py', traceback: Traceback (most recent call last):
  File "/working_dir/llvm-project/llvm/utils/lit/lit/TestingConfig.py", line 129, in load_from_path
    exec(compile(data, path, 'exec'), cfg_globals, None)
  File "/working_dir/standalone/test/lit.cfg.py", line 21, in <module>
    config.test_format = lit.formats.ShTest(not llvm_config.use_lit_shell)
AttributeError: 'NoneType' object has no attribute 'use_lit_shell'

Note ninja check-standalone also works without problems.

Thank you in advance.

This was written some years ago, primarily for cmake-based projects but I hope it’s still helpful.