@@ -147,6 +147,9 @@ guidelines for developing code in a repository:
147147 continuous integration/continuous deployment (CI/CD) pipelines to catch issues early
148148 and ensure reliable deployments. For more information, see `Unit testing `_.
149149
150+ .. note :: No pull request is accepted if the amount of test coverage is not sufficient.
151+ If you are adding new code, ensure that it is covered by existing or new unit tests.
152+
150153#. **Respect code style and standards **: Follow code style
151154 guidelines and adhere to coding standards specific to your language or
152155 framework.
@@ -228,38 +231,6 @@ along with integration tests. The difference between a unit test and an
228231integration test is that the latter tests several units of the code to ensure
229232that they all work together.
230233
231- To run all the unit tests use the following command:
232-
233- .. code :: console
234-
235- (.venv) mapdl@machine:~/pymapdl$ pytest
236-
237- If you are running on a **Linux machine without display **, you must install ``xvfb `` OS
238- library and run the preceding command with the ``xvfb-run `` command as prefix.
239-
240- .. code :: console
241-
242- (.venv) mapdl@machine:~/pymapdl$ xvfb-run pytest
243-
244- In case you want to run only a certain subset of tests, you can use the ``-k `` argument
245- to filter the tests using booleans:
246-
247- .. code :: console
248-
249- (.venv) mapdl@machine:~/pymapdl$ pytest -k "test_nlist_to_array or test_string_with_literal"
250- ==================================================== test session starts ====================================================
251- platform darwin -- Python 3.10.13, pytest-7.4.3, pluggy-1.3.0
252- rootdir: /Users/german.ayuso/pymapdl
253- configfile: pyproject.toml
254- testpaths: tests
255- plugins: timeout-2.2.0, cov-4.1.0, sphinx-0.5.0, rerunfailures-13.0, anyio-4.1.0, pytest_pyvista-0.1.9
256- collected 1468 items / 1466 deselected / 4 skipped / 2 selected
257-
258- tests/test_commands.py .. [100%]
259-
260- =============================================== PyMAPDL Pytest short summary ================================================
261- ======================================= 2 passed, 4 skipped, 1466 deselected in 2.27s =======================================
262-
263234
264235Creation of a unit test
265236-----------------------
@@ -297,34 +268,85 @@ It is executed upstream of each test and not within all tests.
297268
298269 Passing the ``cleared `` fixture is also useful since it clears up the MAPDL database
299270and configuration before performing the test.
300- If you do not have MAPDL installed locally but still want to run the
301- unit testing, you must set up the following environment variables.
302271
303- .. tab-set ::
272+ Running PyMAPDL tests
273+ ---------------------
274+
275+ To run all the unit tests use the following command:
276+
277+ .. code :: console
278+
279+ (.venv) mapdl@machine:~/pymapdl$ pytest
280+
281+ If you just want to run a specific test file, you can provide the path to the file:
282+
283+ .. code :: console
284+
285+ (.venv) mapdl@machine:~/pymapdl$ pytest tests/test_commands.py
286+
287+ In case you want to run only a certain subset of tests, you can use the ``-k `` argument
288+ to filter the tests using booleans:
289+
290+ .. code :: console
304291
305- .. tab-item :: Windows
306- :sync: key1
292+ (.venv) mapdl@machine:~/pymapdl$ pytest -k "test_nlist_to_array or test_string_with_literal"
293+ ======================================= test session starts ====================================================
294+ platform darwin -- Python 3.10.13, pytest-7.4.3, pluggy-1.3.0
295+ rootdir: /Users/german.ayuso/pymapdl
296+ configfile: pyproject.toml
297+ testpaths: tests
298+ plugins: timeout-2.2.0, cov-4.1.0, sphinx-0.5.0, rerunfailures-13.0, anyio-4.1.0, pytest_pyvista-0.1.9
299+ collected 1468 items / 1466 deselected / 4 skipped / 2 selected
307300
308- .. code :: pwsh-session
301+ tests/test_commands.py .. [100%]
309302
310- SET PYMAPDL_START_INSTANCE=False
311- SET PYMAPDL_PORT=<MAPDL Port> (default 50052)
312- SET PYMAPDL_IP=<MAPDL IP> (default 127.0.0.1)
303+ ================================= PyMAPDL Pytest short summary ================================================
304+ ========================= 2 passed, 4 skipped, 1466 deselected in 2.27s =======================================
313305
314- .. tab-item :: Linux
315- :sync: key1
316-
317- .. code :: console
306+ If you are running on a **Linux machine without display ** (for example running from
307+ a container), you must install ``xvfb `` OS library and run the preceding command with the ``xvfb-run `` command as prefix.
318308
319- export PYMAPDL_START_INSTANCE=False
320- export PYMAPDL_PORT=<MAPDL Port> (default 50052)
321- export PYMAPDL_IP=<MAPDL IP> (default 127.0.0.1)
309+ .. code :: console
322310
311+ (.venv) mapdl@machine:~/pymapdl$ xvfb-run pytest
323312
324- These environment variables tell PyMAPDL to attempt to connect to the existing
325- MAPDL service by default when the ``launch_mapdl `` function is used.
326313
327- Additionally, you can use the :envvar: `PYMAPDL_MAPDL_EXEC ` and :envvar: `PYMAPDL_MAPDL_VERSION `
314+ Configuring the test suite
315+ --------------------------
316+
317+ PyMAPDL can operate in multiple situations, or configurations.
318+ To test these different configurations, you can use the `pytest ` framework with specific environment variables.
319+
320+ The list of environment variables that can be set includes:
321+
322+ +-----------------------------------+------------------+-----------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
323+ | Environment variable | Values | Default | Usage |
324+ +===================================+==================+=================+===============================================================================================================================================================================================================================================================+
325+ | :envvar: `ON_CI ` | `True `/`False ` | `False ` | Tell Pytest it is running on GitHub Actions |
326+ +-----------------------------------+------------------+-----------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
327+ | :envvar: `ON_LOCAL ` | `True `/`False ` | Detected | Tell Pytest that PyMAPDL is running on local, and the test should match that. The default is to detect whether MAPDL is installed or not. If the environment variable :envvar: `PYMAPDL_START_INSTANCE ` is set, then :envvar: `ON_LOCAL ` is `False `. |
328+ +-----------------------------------+------------------+-----------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
329+ | :envvar: `ON_UBUNTU ` | `True `/`False ` | Detected | Tell Pytest that PyMAPDL is running on Ubuntu, and the test should match that. |
330+ +-----------------------------------+------------------+-----------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
331+ | :envvar: `ON_STUDENT ` | `True `/`False ` | `False ` | Tell Pytest that PyMAPDL is running on a student environment, and the test should match that. |
332+ +-----------------------------------+------------------+-----------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
333+ | :envvar: `TESTING_MINIMAL ` | `True `/`False ` | `False ` | Tell Pytest that PyMAPDL is installed with the minimal requirements, hence it won't run tests that requires libraries like Pyvista, DPF, etc. |
334+ +-----------------------------------+------------------+-----------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
335+ | :envvar: `PYMAPDL_DEBUG_TESTING ` | `True `/`False ` | `False ` | Tell PyMAPDL to enable debug while testing. This means that the APDL commands are recorded to the file `pymapdl.apdl ` and the debug calls are logged into the file `pymapdl.log `. |
336+ +-----------------------------------+------------------+-----------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
337+ | :envvar: `HAS_GRPC ` | `True `/`False ` | Detected | Tell PyMAPDL that the gRPC interface is available for testing. If `TESTING_MINIMAL ` is `True `, then this is `True ` by default. |
338+ +-----------------------------------+------------------+-----------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
339+ | :envvar: `HAS_DPF ` | `True `/`False ` | `False ` | Tell Pytest that DPF should be tested. |
340+ +-----------------------------------+------------------+-----------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
341+ | :envvar: `DISTRIBUTED_MODE ` | `SMP `/`DMP ` | `SMP ` | Tell Pytest that MAPDL is running a given distributed mode. |
342+ +-----------------------------------+------------------+-----------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
343+ | :envvar: `SUPPORT_PLOTTING ` | `True `/`False ` | Detected | Tell Pytest that the machine supports plotting (it has a display). |
344+ +-----------------------------------+------------------+-----------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
345+ | :envvar: `TEST_DPF_BACKEND ` | `Yes `/`No ` | `NO ` | Tell Pytest that the module `Result ` with DPF backend should be tested. |
346+ +-----------------------------------+------------------+-----------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
347+
348+ Additionally, you can use any :ref: `ref_environment_variables `
349+ like the :envvar: `PYMAPDL_MAPDL_EXEC ` and :envvar: `PYMAPDL_MAPDL_VERSION `
328350environment variables to specify the MAPDL executable path and the version to launch (if
329351multiple versions of MAPDL are installed).
330352
0 commit comments