diff --git a/networkx/algorithms/connectivity/connectivity.py b/networkx/algorithms/connectivity/connectivity.py
index ef31f33a9..bf7916160 100644
--- a/networkx/algorithms/connectivity/connectivity.py
+++ b/networkx/algorithms/connectivity/connectivity.py
@@ -454,12 +454,13 @@ def all_pairs_node_connectivity(G, nbunch=None, flow_func=None):
     else:
         nbunch = set(nbunch)
 
-    if G.is_directed():
+    directed = G.is_directed()
+    if directed:
         iter_func = itertools.permutations
     else:
         iter_func = itertools.combinations
 
-    all_pairs = dict.fromkeys(nbunch, dict())
+    all_pairs = {n: {} for n in nbunch}
 
     # Reuse auxiliary digraph and residual network
     H = build_auxiliary_node_connectivity(G)
@@ -470,6 +471,8 @@ def all_pairs_node_connectivity(G, nbunch=None, flow_func=None):
     for u, v in iter_func(nbunch, 2):
         K = local_node_connectivity(G, u, v, **kwargs)
         all_pairs[u][v] = K
+        if not directed:
+            all_pairs[v][u] = K
 
     return all_pairs
 

bug in all_pairs_node_connectivity
For building the dictionary to store the results I was using:
```python
all_pairs = dict.fromkeys(nbunch, dict())
```
Which is using refrences to the same dict for each node. The tests did not catch this (ouch!), I found out while working on #1405. I'll send a PR fixing it, by using: 
```python
all_pairs = {n: {} for n in nbunch}
```
I'll also add tests.
diff --git a/networkx/algorithms/connectivity/tests/test_connectivity.py b/networkx/algorithms/connectivity/tests/test_connectivity.py
index 93420ae76..6b0b8af4a 100644
--- a/networkx/algorithms/connectivity/tests/test_connectivity.py
+++ b/networkx/algorithms/connectivity/tests/test_connectivity.py
@@ -279,7 +279,58 @@ def test_edge_connectivity_flow_vs_stoer_wagner():
         G = graph_func()
         assert_equal(nx.stoer_wagner(G)[0], nx.edge_connectivity(G))
 
-class TestConnectivityPairs(object):
+
+class TestAllPairsNodeConnectivity:
+
+    def setUp(self):
+        self.path = nx.path_graph(7)
+        self.directed_path = nx.path_graph(7, create_using=nx.DiGraph())
+        self.cycle = nx.cycle_graph(7)
+        self.directed_cycle = nx.cycle_graph(7, create_using=nx.DiGraph())
+        self.gnp = nx.gnp_random_graph(30, 0.1)
+        self.directed_gnp = nx.gnp_random_graph(30, 0.1, directed=True)
+        self.K20 = nx.complete_graph(20)
+        self.K10 = nx.complete_graph(10)
+        self.K5 = nx.complete_graph(5)
+        self.G_list = [self.path, self.directed_path, self.cycle,
+            self.directed_cycle, self.gnp, self.directed_gnp, self.K10,
+            self.K5, self.K20]
+
+    def test_cycles(self):
+        K_undir = nx.all_pairs_node_connectivity(self.cycle)
+        for source in K_undir:
+            for target, k in K_undir[source].items():
+                assert_true(k == 2)
+        K_dir = nx.all_pairs_node_connectivity(self.directed_cycle)
+        for source in K_dir:
+            for target, k in K_dir[source].items():
+                assert_true(k == 1)
+
+    def test_complete(self):
+        for G in [self.K10, self.K5, self.K20]:
+            K = nx.all_pairs_node_connectivity(G)
+            for source in K:
+                for target, k in K[source].items():
+                    assert_true(k == len(G)-1)
+
+    def test_paths(self):
+        K_undir = nx.all_pairs_node_connectivity(self.path)
+        for source in K_undir:
+            for target, k in K_undir[source].items():
+                assert_true(k == 1)
+        K_dir = nx.all_pairs_node_connectivity(self.directed_path)
+        for source in K_dir:
+            for target, k in K_dir[source].items():
+                if source < target:
+                    assert_true(k == 1)
+                else:
+                    assert_true(k == 0)
+
+    def test_all_pairs_connectivity_nbunch(self):
+        G = nx.complete_graph(5)
+        nbunch = [0, 2, 3]
+        C = nx.all_pairs_node_connectivity(G, nbunch=nbunch)
+        assert_equal(len(C), len(nbunch))
 
     def test_all_pairs_connectivity_icosahedral(self):
         G = nx.icosahedral_graph()
@@ -290,9 +341,9 @@ class TestConnectivityPairs(object):
         G = nx.Graph()
         nodes = [0, 1, 2, 3]
         G.add_path(nodes)
-        A = dict.fromkeys(G, dict())
+        A = {n: {} for n in G}
         for u, v in itertools.combinations(nodes,2):
-            A[u][v] = nx.node_connectivity(G, u, v)
+            A[u][v] = A[v][u] = nx.node_connectivity(G, u, v)
         C = nx.all_pairs_node_connectivity(G)
         assert_equal(sorted((k, sorted(v)) for k, v in A.items()),
                      sorted((k, sorted(v)) for k, v in C.items()))
@@ -301,7 +352,7 @@ class TestConnectivityPairs(object):
         G = nx.DiGraph()
         nodes = [0, 1, 2, 3]
         G.add_path(nodes)
-        A = dict.fromkeys(G, dict())
+        A = {n: {} for n in G}
         for u, v in itertools.permutations(nodes, 2):
             A[u][v] = nx.node_connectivity(G, u, v)
         C = nx.all_pairs_node_connectivity(G)
@@ -311,9 +362,9 @@ class TestConnectivityPairs(object):
     def test_all_pairs_connectivity_nbunch(self):
         G = nx.complete_graph(5)
         nbunch = [0, 2, 3]
-        A = dict.fromkeys(nbunch, dict())
+        A = {n: {} for n in nbunch}
         for u, v in itertools.combinations(nbunch, 2):
-            A[u][v] = nx.node_connectivity(G, u, v)
+            A[u][v] = A[v][u] = nx.node_connectivity(G, u, v)
         C = nx.all_pairs_node_connectivity(G, nbunch=nbunch)
         assert_equal(sorted((k, sorted(v)) for k, v in A.items()),
                      sorted((k, sorted(v)) for k, v in C.items()))
@@ -321,9 +372,9 @@ class TestConnectivityPairs(object):
     def test_all_pairs_connectivity_nbunch_iter(self):
         G = nx.complete_graph(5)
         nbunch = [0, 2, 3]
-        A = dict.fromkeys(nbunch, dict())
+        A = {n: {} for n in nbunch}
         for u, v in itertools.combinations(nbunch, 2):
-            A[u][v] = nx.node_connectivity(G, u, v)
+            A[u][v] = A[v][u] = nx.node_connectivity(G, u, v)
         C = nx.all_pairs_node_connectivity(G, nbunch=iter(nbunch))
         assert_equal(sorted((k, sorted(v)) for k, v in A.items()),
                      sorted((k, sorted(v)) for k, v in C.items()))

pip install -e .
parse_log_pytest
requirements.txt
nose pytest
apt-get update apt-get install -y libgdal-dev graphviz
3.6
requirements/default.txt requirements/test.txt
pytest --no-header -rA --tb=line --color=no -p no:cacheprovider -W ignore::DeprecationWarning
attrs==22.2.0
certifi==2021.5.30
decorator==5.1.1
importlib-metadata==4.8.3
iniconfig==1.1.1
-e git+https://github.com/networkx/networkx.git@33c39a05c03d699d76c4e4194ffeb9d818ee3934#egg=networkx
nose==1.3.7
packaging==21.3
pluggy==1.0.0
py==1.11.0
pyparsing==3.1.4
pytest==7.0.1
tomli==1.2.3
typing_extensions==4.1.1
zipp==3.6.0

name: networkx
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==5.1.1
      - importlib-metadata==4.8.3
      - iniconfig==1.1.1
      - nose==1.3.7
      - packaging==21.3
      - pluggy==1.0.0
      - py==1.11.0
      - pyparsing==3.1.4
      - pytest==7.0.1
      - tomli==1.2.3
      - typing-extensions==4.1.1
      - zipp==3.6.0
prefix: /opt/conda/envs/networkx

networkx/algorithms/connectivity/tests/test_connectivity.py::TestAllPairsNodeConnectivity::test_all_pairs_connectivity_nbunch networkx/algorithms/connectivity/tests/test_connectivity.py::TestAllPairsNodeConnectivity::test_all_pairs_connectivity networkx/algorithms/connectivity/tests/test_connectivity.py::TestAllPairsNodeConnectivity::test_all_pairs_connectivity_directed networkx/algorithms/connectivity/tests/test_connectivity.py::TestAllPairsNodeConnectivity::test_all_pairs_connectivity_nbunch_iter
networkx/algorithms/connectivity/tests/test_connectivity.py::TestAllPairsNodeConnectivity::test_cycles networkx/algorithms/connectivity/tests/test_connectivity.py::TestAllPairsNodeConnectivity::test_complete networkx/algorithms/connectivity/tests/test_connectivity.py::TestAllPairsNodeConnectivity::test_paths
networkx/algorithms/connectivity/tests/test_connectivity.py::test_average_connectivity networkx/algorithms/connectivity/tests/test_connectivity.py::test_average_connectivity_directed networkx/algorithms/connectivity/tests/test_connectivity.py::test_articulation_points networkx/algorithms/connectivity/tests/test_connectivity.py::test_brandes_erlebach networkx/algorithms/connectivity/tests/test_connectivity.py::test_white_harary_1 networkx/algorithms/connectivity/tests/test_connectivity.py::test_white_harary_2 networkx/algorithms/connectivity/tests/test_connectivity.py::test_complete_graphs networkx/algorithms/connectivity/tests/test_connectivity.py::test_empty_graphs networkx/algorithms/connectivity/tests/test_connectivity.py::test_petersen networkx/algorithms/connectivity/tests/test_connectivity.py::test_tutte networkx/algorithms/connectivity/tests/test_connectivity.py::test_dodecahedral networkx/algorithms/connectivity/tests/test_connectivity.py::test_octahedral networkx/algorithms/connectivity/tests/test_connectivity.py::test_icosahedral networkx/algorithms/connectivity/tests/test_connectivity.py::test_missing_source networkx/algorithms/connectivity/tests/test_connectivity.py::test_missing_target networkx/algorithms/connectivity/tests/test_connectivity.py::test_edge_missing_source networkx/algorithms/connectivity/tests/test_connectivity.py::test_edge_missing_target networkx/algorithms/connectivity/tests/test_connectivity.py::test_not_weakly_connected networkx/algorithms/connectivity/tests/test_connectivity.py::test_not_connected networkx/algorithms/connectivity/tests/test_connectivity.py::test_directed_edge_connectivity networkx/algorithms/connectivity/tests/test_connectivity.py::test_cutoff networkx/algorithms/connectivity/tests/test_connectivity.py::test_invalid_auxiliary networkx/algorithms/connectivity/tests/test_connectivity.py::test_interface_only_source networkx/algorithms/connectivity/tests/test_connectivity.py::test_interface_only_target networkx/algorithms/connectivity/tests/test_connectivity.py::test_edge_connectivity_flow_vs_stoer_wagner networkx/algorithms/connectivity/tests/test_connectivity.py::TestAllPairsNodeConnectivity::test_all_pairs_connectivity_icosahedral
networkx/algorithms/connectivity/connectivity.py
networkx/algorithms/connectivity/connectivity.py