diff --git a/cellmlmanip/model.py b/cellmlmanip/model.py
index de9aec1..fae9c45 100644
--- a/cellmlmanip/model.py
+++ b/cellmlmanip/model.py
@@ -278,8 +278,8 @@ class Model(object):
         lhs_units = self.units.evaluate_units(equality.lhs)
         rhs_units = self.units.evaluate_units(equality.rhs)
         assert self.units.is_equivalent(rhs_units, lhs_units), 'Units %s %s != %s %s' % (
-            lhs_units, self.units.show_base_units(lhs_units),
-            rhs_units, self.units.show_base_units(rhs_units)
+            self.units.format(lhs_units), self.units.format(lhs_units, True),
+            self.units.format(rhs_units), self.units.format(rhs_units, True),
         )
 
     def get_equations_for(self, symbols, recurse=True, strip_units=True):
diff --git a/cellmlmanip/units.py b/cellmlmanip/units.py
index 691a5ed..a6ea6c0 100644
--- a/cellmlmanip/units.py
+++ b/cellmlmanip/units.py
@@ -57,6 +57,9 @@ _TRIG_FUNCTIONS = {
 # It says (1) not preceded by a number or period, (2) then at least one ascii letter, (3) then numbers or _ allowed too
 _WORD = re.compile('(?<![0-9.])[a-zA-Z_]+[a-zA-Z0-9_]*')
 
+# Regex to remove UnitStore prefixes
+_STORE_PREFIX = re.compile('(?<![a-zA-Z0-9_])store[0-9]+_')
+
 
 class UnitError(Exception):
     """Base class for errors relating to calculating units."""
@@ -186,7 +189,7 @@ class UnitStore(object):
         # same registry.
         self._id = UnitStore._next_id
         UnitStore._next_id += 1
-        self._prefix = 's' + str(self._id) + '_'
+        self._prefix = 'store' + str(self._id) + '_'
 
         # Get unit registry
         if store is None:
@@ -280,6 +283,22 @@ class UnitStore(object):
         assert isinstance(unit, self._registry.Unit)
         return quantity.to(unit)
 
+    def format(self, unit, base_units=False):
+        """
+        Returns a string representation of a unit.
+
+        :param unit: The ``Unit`` object to format.
+        :param base_units: If this optional argument is set to ``True`` the string will show the base units expansion of
+            the given unit.
+        """
+        if base_units:
+            base = self._registry.get_base_units(unit)
+            text = str(base[0]) + ' ' + str(base[1])
+            # Remove unit store prefixes from any unit store
+            return _STORE_PREFIX.sub('', text)
+        else:
+            return _STORE_PREFIX.sub('', str(unit))
+
     def get_unit(self, name):
         """Retrieves the ``Unit`` object with the given name.
 
@@ -349,14 +368,6 @@ class UnitStore(object):
 
         return self._prefix + name
 
-    def show_base_units(self, unit):
-        """
-        Returns a string show the base units of the given unit.
-        """
-        base = self._registry.get_base_units(unit)
-        text = str(base[0]) + ' ' + str(base[1])
-        return text.replace(self._prefix, '')
-
 
 class UnitCalculator(object):
     """

Add method to obtain unit name
Given a `pint.unit` we'd like to know its name. This used to be possible with `str(unit)` but that now adds a prefix we need to strip
diff --git a/tests/test_parser.py b/tests/test_parser.py
index b6ade76..f7232ad 100644
--- a/tests/test_parser.py
+++ b/tests/test_parser.py
@@ -218,7 +218,7 @@ class TestParser(object):
         p = parser.Parser(cellml)
         m = p.parse()
         i = m.units.get_unit('inch')
-        assert m.units.show_base_units(i) == '0.0254 meter'
+        assert m.units.format(i, True) == '0.0254 meter'
 
     def test_undefined_variable(self):
         """ Tests parser exception for undefined variable. """
diff --git a/tests/test_units.py b/tests/test_units.py
index e2c179d..551406a 100644
--- a/tests/test_units.py
+++ b/tests/test_units.py
@@ -57,9 +57,9 @@ class TestUnits(object):
 
         unitstore = UnitStore()
         assert not unitstore.is_defined('uu')
-        unitstore.add_base_unit('uu')
+        uu = unitstore.add_base_unit('uu')
         assert unitstore.is_defined('uu')
-        assert unitstore.show_base_units(unitstore.get_unit('uu')) == '1.0 uu'
+        assert unitstore.format(uu, True) == '1.0 uu'
 
         # Duplicate unit definition
         with pytest.raises(ValueError):
@@ -78,6 +78,25 @@ class TestUnits(object):
         y = store.convert(x, mm)
         assert y == 5000 * mm
 
+    def test_format(self):
+        """Tests formatting of units."""
+
+        # Test basic formatting and base unit expansion
+        store = UnitStore()
+        store.add_unit('x', 'second')
+        y = store.add_base_unit('y')
+        z = store.add_unit('z', 'y * meter / x ** 2')
+        assert store.format(z) == 'z'
+        assert store.format(z, True) == '1.0 meter * y / second ** 2'
+
+        # Test if internal name manipulation can mess things up
+        a = store.add_base_unit(str(y))
+        b = store.add_unit(str(z), '2 * z /' + str(y))
+        assert store.format(a) == str(y)
+        assert store.format(b) == str(z)
+        assert store.format(a, True) == '1.0 ' + str(y)
+        assert store.format(b, True) == '2.0 meter * y / second ** 2 / ' + str(y)
+
     def test_get_unit(self):
         """Tests UnitStore.get_unit()."""
 

pip install -e .[dev]
parse_log_pytest
requirements.txt
pytest
3.6
requirements/base.txt
pytest --no-header -rA --tb=line --color=no -p no:cacheprovider -W ignore::DeprecationWarning
attrs==22.2.0
-e git+https://github.com/ModellingWebLab/cellmlmanip.git@b55a11ecbaa653350dd1c686cadaeec6005aee9c#egg=cellmlmanip
certifi==2021.5.30
decorator==4.4.0
importlib-metadata==4.8.3
iniconfig==1.1.1
isodate==0.6.0
lxml==4.4.1
mpmath==1.1.0
networkx==2.3
packaging==21.3
Pint==0.9
pluggy==1.0.0
py==1.11.0
pyparsing==2.4.2
pytest==7.0.1
rdflib==4.2.2
six==1.12.0
sympy==1.4
tomli==1.2.3
typing_extensions==4.1.1
zipp==3.6.0

name: cellmlmanip
channels:
  - defaults
  - https://repo.anaconda.com/pkgs/main
  - https://repo.anaconda.com/pkgs/r
  - conda-forge
dependencies:
  - _libgcc_mutex=0.1=main
  - _openmp_mutex=5.1=1_gnu
  - ca-certificates=2025.2.25=h06a4308_0
  - certifi=2021.5.30=py36h06a4308_0
  - ld_impl_linux-64=2.40=h12ee557_0
  - libffi=3.3=he6710b0_2
  - libgcc-ng=11.2.0=h1234567_1
  - libgomp=11.2.0=h1234567_1
  - libstdcxx-ng=11.2.0=h1234567_1
  - ncurses=6.4=h6a678d5_0
  - openssl=1.1.1w=h7f8727e_0
  - pip=21.2.2=py36h06a4308_0
  - python=3.6.13=h12debd9_1
  - readline=8.2=h5eee18b_0
  - setuptools=58.0.4=py36h06a4308_0
  - sqlite=3.45.3=h5eee18b_0
  - tk=8.6.14=h39e8969_0
  - wheel=0.37.1=pyhd3eb1b0_0
  - xz=5.6.4=h5eee18b_1
  - zlib=1.2.13=h5eee18b_1
  - pip:
      - attrs==22.2.0
      - decorator==4.4.0
      - importlib-metadata==4.8.3
      - iniconfig==1.1.1
      - isodate==0.6.0
      - lxml==4.4.1
      - mpmath==1.1.0
      - networkx==2.3
      - packaging==21.3
      - pint==0.9
      - pluggy==1.0.0
      - py==1.11.0
      - pyparsing==2.4.2
      - pytest==7.0.1
      - rdflib==4.2.2
      - six==1.12.0
      - sympy==1.4
      - tomli==1.2.3
      - typing-extensions==4.1.1
      - zipp==3.6.0
prefix: /opt/conda/envs/cellmlmanip

tests/test_parser.py::TestParser::test_units_with_multiplier tests/test_units.py::TestUnits::test_add_base_unit tests/test_units.py::TestUnits::test_format
tests/test_parser.py::TestParser::test_component_count tests/test_parser.py::TestParser::test_group_relationships tests/test_parser.py::TestParser::test_equations_count tests/test_parser.py::TestParser::test_rdf tests/test_parser.py::TestParser::test_connections_loaded tests/test_parser.py::TestParser::test_connections tests/test_parser.py::TestParser::test_add_units_to_equations tests/test_parser.py::TestParser::test_connect_to_hidden_component tests/test_parser.py::TestParser::test_bad_connection_units tests/test_parser.py::TestParser::test_new_base_units tests/test_parser.py::TestParser::test_undefined_variable tests/test_parser.py::TestParser::test_multiple_math_elements tests/test_parser.py::TestParser::test_bad_unit_definitions tests/test_parser.py::TestParser::test_component_units_unsupported tests/test_parser.py::TestParser::test_reactions_unsupported tests/test_parser.py::TestParser::test_validation tests/test_units.py::TestUnits::test_add_unit tests/test_units.py::TestUnits::test_convert tests/test_units.py::TestUnits::test_get_unit tests/test_units.py::TestUnits::test_is_equivalent tests/test_units.py::TestUnits::test_get_conversion_factor tests/test_units.py::TestUnits::test_prefixing tests/test_units.py::TestUnits::test_shared_registry tests/test_units.py::TestEvaluateUnits::test_numbers tests/test_units.py::TestEvaluateUnits::test_others
cellmlmanip/model.py cellmlmanip/units.py
cellmlmanip/model.py cellmlmanip/units.py