
import os

__all__ = ["test_util", "test_clean"]

for file_ in os.listdir(os.path.dirname(__file__)):
    if file_.startswith('test_') and file_.endswith('.py'):
        __all__.append(file_.rsplit('.py', 1)[0])


from os import path
import glob

test_modules = [path.splitext(path.basename(filename))[0] for filename in glob.glob(path.join(path.dirname(__file__), 'test*.py'))]
__all__ = test_modules

Improve detecting available test modules in test package
Improve detecting available test modules in test package

By using glob and path.splitext instead of manually iterating over files
in the directory and filtering out files based on their names.

  
+ from os import path
- import os
+ import glob
  
- __all__ = ["test_util", "test_clean"]
+ test_modules = [path.splitext(path.basename(filename))[0] for filename in glob.glob(path.join(path.dirname(__file__), 'test*.py'))]
+ __all__ = test_modules
  
- for file_ in os.listdir(os.path.dirname(__file__)):
-     if file_.startswith('test_') and file_.endswith('.py'):
-         __all__.append(file_.rsplit('.py', 1)[0])
- 
Improve detecting available test modules in test package
## Code Before:

import os

__all__ = ["test_util", "test_clean"]

for file_ in os.listdir(os.path.dirname(__file__)):
    if file_.startswith('test_') and file_.endswith('.py'):
        __all__.append(file_.rsplit('.py', 1)[0])

## Instruction:
Improve detecting available test modules in test package
## Code After:

from os import path
import glob

test_modules = [path.splitext(path.basename(filename))[0] for filename in glob.glob(path.join(path.dirname(__file__), 'test*.py'))]
__all__ = test_modules
