Private Elements¶
Command Line Arguments¶
Module: _ptcsvp.cmdline
This pytest plugin requires command line arguments that are parsed from the pytest framework. This module contains code to instruct pytest to deliver the required values.
- _ptcsvp.cmdline.HELP_TEXT = 'set base dir for getting CSV data files from'¶
This is the help text for the command line arguments that is added by
pytest_addoption()
.
Plugin Configuration¶
Module: _ptcsvp.configure
The pytest plugin needs a setup (pytest_configure()
) and a teardown (pytest_unconfigure()
) method registered. This module contains the required methods for that.
- _ptcsvp.configure.pytest_configure(config, plugin_name='csv_params')¶
Register our Plugin
The Parametrization¶
Module: _ptcsvp.parametrize
Parametrize a test function by CSV file
- class _ptcsvp.parametrize.TestCaseParameters¶
Type for a single test case. Contains the optional
test_id
and the testdata
.
- _ptcsvp.parametrize.add_parametrization(data_file, base_dir=None, id_col=None, data_casts=None, dialect=CsvParamsDefaultDialect, header_renames=None)¶
Parametrize a test function with data from a CSV file.
For the public decorator, see
pytest_csv_params.decorator.csv_params()
.- Parameters:
data_file (
str
) – The CSV file to read the data frombase_dir (
Optional
[str
]) – Optional base directory to look for non-absolutedata_file
inid_col (
Optional
[str
]) – Optional name of a column that shall be used to make the test IDs fromdata_casts (
Optional
[Dict
[str
,Callable
[[str
],Any
]]]) – Methods to cast a column’s data into a format that is required for the testdialect (
Type
[Dialect
]) – The CSV file dialect (CSV file format) to useheader_renames (
Optional
[Dict
[str
,str
]]) – A dictonary mapping the header names from the CSV file to usable names for the tests
- Return type:
MarkDecorator
- Returns:
pytest.mark.parametrize()
mark decorator, filled with all the data from the CSV.
- _ptcsvp.parametrize.clean_headers(current_headers, replacing)¶
Clean the CSV file headers
- Parameters:
- Return type:
- Returns:
List of cleaned header names
- Raises:
CsvHeaderNameInvalid – When non-unique names appear
- _ptcsvp.parametrize.read_csv(base_dir, data_file, dialect)¶
Get Data from CSV
- Parameters:
base_dir (
Optional
[str
]) – Optional directory to look up non-absolute CSV files (given asdata_file
)data_file (
str
) – The CSV file to read. If this is an absolute path,base_dir
will be ignored; if not, thebase_dir
is prepended.dialect (
Type
[Dialect
]) – The CSV file dialect (definition of the format of a CSV file).
- Return type:
- Returns:
A list of rows, each row contains a list of columns; all type str
The Plugin Class¶
Module: _ptcsvp.plugin
This module contains the main plugin class. By the time of writing, it is quite unspectacular.
- _ptcsvp.plugin.BASE_DIR_KEY = '__pytest_csv_params__config__base_dir'¶
The class attribute key for
Plugin
to store the base dir command line argument value.
- class _ptcsvp.plugin.Plugin(config)¶
The main plugin class
Currently, this class is nothing more than the keeper of the value of the command line argument (as defined by
_ptcsvp.cmdline.pytest_addoption()
.
The Variable Name Validation¶
Module: _ptcsvp.varname
This module contains code to validate variable/argument/parameter names or to make them valid ones.
- _ptcsvp.varname.VALID_CHARS = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'¶
Valid characters a variable/parameter/argument name can consist of
- _ptcsvp.varname.VARIABLE_NAME = re.compile('^[a-zA-Z_][A-Za-z0-9_]{0,1023}$')¶
Regular expression that defines a valid variable/parameter/argument name
- _ptcsvp.varname.is_valid_name(name)¶
Checks if the variable name is valid
- _ptcsvp.varname.make_name_valid(name, replacement_char='_')¶
Make a name a valid name by replacing invalid chars with the as
replacement_char
given char- Parameters:
- Return type:
- Returns:
A valid name
- Raises:
CsvHeaderNameInvalid – If the fixed name is still an invalid name
The Version Checks¶
Module: _ptcsvp.version
This module contains two methods to check if the python version is recent enough (check_python_version()
) and if the pytest version is recent enough (check_pytest_version()
).
During the setup phase of the plugin (see pytest_csv_params.plugin
) these methods are called.
- _ptcsvp.version.check_pytest_version(min_version=(7, 4))¶
Check if the current version is at least 7.4
- Parameters:
min_version (
Tuple
[int
,int
]) – The minimum version required, as tuple, default is 7.4- Raises:
RuntimeError – When the pytest version is too old/unsupported
- Return type: