|
1 | | -## Rule |
| 1 | +## Checks before committing |
2 | 2 |
|
3 | | -Do `ruff format` and `ruff check` before commit. |
| 3 | +Run commands from the repository root. Format and lint the source before |
| 4 | +committing: |
4 | 5 |
|
5 | | -## Running the MySQL test suite in this container |
| 6 | +```sh |
| 7 | +ruff format src/ |
| 8 | +ruff check src/ |
| 9 | +git diff --check |
| 10 | +``` |
6 | 11 |
|
7 | | -1. Install the server and test dependencies if they are not already available: |
| 12 | +## Running the mysqlclient test suite |
8 | 13 |
|
9 | | - ```sh |
10 | | - apt-get update |
11 | | - DEBIAN_FRONTEND=noninteractive apt-get install -y mysql-server |
12 | | - python -m pip install --upgrade -r requirements-dev.txt |
13 | | - ``` |
| 14 | +The CI configuration is in [.github/workflows/tests.yaml](.github/workflows/tests.yaml). |
| 15 | +The package is in `src/MySQLdb/` and the tests are in `tests/`. |
| 16 | + |
| 17 | +1. Install a C compiler, Python development headers, `pkg-config`, and MySQL or |
| 18 | + MariaDB client development libraries, as described in [README.md](README.md). |
| 19 | + A running MySQL or MariaDB server is also required for database tests. |
14 | 20 |
|
15 | | -2. Keep MySQL running in a separate, long-lived terminal/session. The container |
16 | | - does not run systemd, so start `mysqld` directly instead of using |
17 | | - `systemctl`: |
| 21 | +2. In a Python virtual environment, install the package and test dependencies: |
18 | 22 |
|
19 | 23 | ```sh |
20 | | - install -d -o mysql -g mysql /run/mysqld |
21 | | - rm -f /run/mysqld/mysqld.sock /run/mysqld/mysqld.sock.lock \ |
22 | | - /run/mysqld/mysqlx.sock /run/mysqld/mysqlx.sock.lock \ |
23 | | - /run/mysqld/mysqld.pid |
24 | | - mysqld --user=mysql --local-infile=1 \ |
25 | | - --socket=/run/mysqld/mysqld.sock \ |
26 | | - --pid-file=/run/mysqld/mysqld.pid |
| 24 | + python -m pip install -v . |
| 25 | + python -m pip install -r requirements.txt |
| 26 | + python -m pip install "SQLAlchemy>=2,<3" |
27 | 27 | ``` |
28 | 28 |
|
29 | | -3. In another terminal/session, wait for MySQL and initialize a fresh data |
30 | | - directory. The SQL files create databases and users, so only run them when |
31 | | - `test1` does not exist: |
| 29 | + SQLAlchemy is needed to run `tests/test_sqlalchemy.py`; those tests are |
| 30 | + skipped if it is not installed. |
| 31 | + |
| 32 | +3. Start the database server using the service manager available in your |
| 33 | + environment. In containers without a service manager, run `mysqld` in a |
| 34 | + separate, long-lived terminal with an initialized data directory and writable |
| 35 | + socket and PID file locations. |
| 36 | + |
| 37 | + Create a dedicated test database using an administrator connection, for example: |
32 | 38 |
|
33 | 39 | ```sh |
34 | | - until mysqladmin ping --silent; do sleep 1; done |
35 | | - if ! mysql -NBe "SHOW DATABASES LIKE 'test1'" | rg -q '^test1$'; then |
36 | | - mysql -uroot --comments < ci/docker-entrypoint-initdb.d/init.sql |
37 | | - mysql -uroot --comments < ci/docker-entrypoint-initdb.d/mysql.sql |
38 | | - mysql -uroot --comments < ci/docker-entrypoint-initdb.d/mariadb.sql |
39 | | - fi |
40 | | - cp ci/docker.json pymysql/tests/databases.json |
| 40 | + mysql -uroot -p -e "CREATE DATABASE IF NOT EXISTS mysqldb_test" |
41 | 41 | ``` |
42 | 42 |
|
43 | | -4. Run the same test commands as CI: |
| 43 | + The test user needs to create, alter, and drop tables, run `SELECT`, |
| 44 | + `INSERT`, `UPDATE`, and `DELETE`, and create, execute, and drop stored |
| 45 | + procedures in that database. |
| 46 | + `tests/actions.cnf` uses `127.0.0.1:3306`, user `root`, password `root`, and |
| 47 | + database `mysqldb_test`. For different credentials, create a separate MySQL |
| 48 | + option file with a `[MySQLdb-tests]` group, using `tests/actions.cnf` as a |
| 49 | + template. |
| 50 | + |
| 51 | +4. Run the same pytest command as CI: |
44 | 52 |
|
45 | 53 | ```sh |
46 | | - pytest -v --cov --cov-config .coveragerc pymysql |
47 | | - pytest -v --cov-append --cov-config .coveragerc \ |
48 | | - --doctest-modules pymysql/converters.py |
| 54 | + TESTDB=actions.cnf pytest --cov=MySQLdb tests |
49 | 55 | ``` |
| 56 | + |
| 57 | + `TESTDB` selects a filename under `tests/` or an absolute path to an option |
| 58 | + file. Without it, `tests/default.cnf` is used. The tests create and drop |
| 59 | + tables, so use the dedicated test database. |
| 60 | + |
| 61 | +CI also runs the Django test suite in a separate job. Refer to |
| 62 | +`.github/workflows/tests.yaml` for its dependencies, database setup, and |
| 63 | +`test_mysql_executemany_multi` settings. |
| 64 | + |
| 65 | +## Releases |
| 66 | + |
| 67 | +Follow [notes/release.md](notes/release.md) for version updates, release CI, |
| 68 | +tagging, and publication. |
0 commit comments